home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / touchup / part05 < prev    next >
Encoding:
Text File  |  1988-06-14  |  71.5 KB  |  2,682 lines

  1. Newsgroups: comp.sources.unix
  2. Subject: v15i062:  A bitmap editor for Suns, Part05/06
  3. Approved: rsalz@uunet.UU.NET
  4.  
  5. Submitted-by: Raymond T Kreisel <rayk@sbcs.sunysb.edu>
  6. Posting-number: Volume 15, Issue 62
  7. Archive-name: touchup/part05
  8.  
  9. THIS IS A COMPLETE REPOSTING OF THE ENTIRE PACKAGE.
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 5 (of 6)."
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f brush.c -a "${1}" != "-c" ; then 
  20.   echo shar: Will not over-write existing file \"brush.c\"
  21. else
  22. echo shar: Extracting \"brush.c\" \(2058 characters\)
  23. sed "s/^X//" >brush.c <<'END_OF_brush.c'
  24. X
  25. X/**************************************************************************
  26. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  27. X   Copyright (c) 1988 by Raymond Kreisel
  28. X   1/22/88 @ Suny Stony Brook
  29. X
  30. X   This program may be redistributed without fee as long as this copyright
  31. X   notice is intact.
  32. X
  33. X==> PLEASE send comments and bug reports to one of the following addresses:
  34. X
  35. X       Ray Kreisel
  36. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  37. X
  38. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  39. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  40. X       CSnet: rayk@suny-sb
  41. X       (If nobody is home at any of the above addresses try:
  42. X        S72QKRE@TOWSONVX.BITNET                    )
  43. X
  44. X "If I get home before daylight, I just might get some sleep tonight...."
  45. X
  46. X**************************************************************************/
  47. X
  48. X#include <pixrect/pixrect_hs.h>
  49. X
  50. X/**************************************************************************
  51. X    file: brush.c
  52. X    purpose: This file contains all that differents brush styles.
  53. X        Brushes can be created with iconedit, using the upper
  54. X        righthand 32x32 bits.  The 64x64 image from iconedit
  55. X        is then stripped to 32x32 by strip_icon32x32
  56. X
  57. X    modifications:
  58. X        date:    Tue Mar 22 22:04:58 EST 1988
  59. X        author:    rayk
  60. X        changes:add comments
  61. X**************************************************************************/
  62. X
  63. Xstatic short brush1_data[] = {
  64. X#include "brush1.icon.pat"
  65. X};
  66. Xstatic mpr_static(brush1_pr, 32, 32, 1, brush1_data);
  67. X
  68. Xstatic short brush2_data[] = {
  69. X#include "brush2.icon.pat"
  70. X};
  71. Xstatic mpr_static(brush2_pr, 32, 32, 1, brush2_data);
  72. X
  73. Xstatic short brush3_data[] = {
  74. X#include "brush3.icon.pat"
  75. X};
  76. Xstatic mpr_static(brush3_pr, 32, 32, 1, brush3_data);
  77. X
  78. Xstatic short brush4_data[] = {
  79. X#include "brush4.icon.pat"
  80. X};
  81. Xstatic mpr_static(brush4_pr, 32, 32, 1, brush4_data);
  82. X
  83. Xstatic short brush5_data[] = {
  84. X#include "brush5.icon.pat"
  85. X};
  86. Xstatic mpr_static(brush5_pr, 32, 32, 1, brush5_data);
  87. X
  88. Xstatic short brush6_data[] = {
  89. X#include "brush6.icon.pat"
  90. X};
  91. Xstatic mpr_static(brush6_pr, 32, 32, 1, brush6_data);
  92. END_OF_brush.c
  93. if test 2058 -ne `wc -c <brush.c`; then
  94.     echo shar: \"brush.c\" unpacked with wrong size!
  95. fi
  96. # end of overwriting check
  97. fi
  98. if test -f circle.c -a "${1}" != "-c" ; then 
  99.   echo shar: Will not over-write existing file \"circle.c\"
  100. else
  101. echo shar: Extracting \"circle.c\" \(3577 characters\)
  102. sed "s/^X//" >circle.c <<'END_OF_circle.c'
  103. X
  104. X/**************************************************************************
  105. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  106. X   Copyright (c) 1988 by Raymond Kreisel
  107. X   1/22/88 @ Suny Stony Brook
  108. X
  109. X   This program may be redistributed without fee as long as this copyright
  110. X   notice is intact.
  111. X
  112. X==> PLEASE send comments and bug reports to one of the following addresses:
  113. X
  114. X       Ray Kreisel
  115. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  116. X
  117. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  118. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  119. X       CSnet: rayk@suny-sb
  120. X       (If nobody is home at any of the above addresses try:
  121. X        S72QKRE@TOWSONVX.BITNET                    )
  122. X
  123. X "If I get home before daylight, I just might get some sleep tonight...."
  124. X
  125. X**************************************************************************/
  126. X
  127. X/**************************************************************************
  128. X    file: circle.c
  129. X    purpose: This file contains that routines that draw circles
  130. X        on the screen. A UNDOCUMENTED Sunview function "pw_polypoint"
  131. X        is used to get the list of points that make the circle
  132. X        on to the screen AMAZINGLY FAST.
  133. X        The points that make up the circle are calculated with
  134. X        bresenhams (sp?) incremental circle algorithm.
  135. X
  136. X    modifications:
  137. X        date:    Tue Mar 22 22:04:58 EST 1988
  138. X        author:    rayk
  139. X        changes:add comments
  140. X**************************************************************************/
  141. X
  142. X#include "header.h"
  143. X
  144. Xstruct  pr_pos  ptlist[MAX_PTS];
  145. X
  146. Xdraw_circle(pw, center_x,center_y, radius,ROP)
  147. Xint        center_x,center_y;
  148. XPixwin            *pw;
  149. Xint                radius,ROP;
  150. X{
  151. Xstruct pr_pos      center;
  152. X
  153. X        int             x,y,
  154. X                        error, numpts;
  155. X
  156. X    if (radius==0) return(0);
  157. X    center.x = center_x;
  158. X    center.y = center_y;
  159. X
  160. X           x = 0; y = radius; numpts = 0;
  161. X           error = 3 - (radius << 1);
  162. X
  163. X           while (x < y)
  164. X           {
  165. X             ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y+y;
  166. X             ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y+y;
  167. X             ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y-y;
  168. X             ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y-y;
  169. X             ptlist[numpts].x=center.x+y;   ptlist[numpts++].y=center.y+x;
  170. X             ptlist[numpts].x=center.x-y;   ptlist[numpts++].y=center.y+x;
  171. X             ptlist[numpts].x=center.x+y;   ptlist[numpts++].y=center.y-x;
  172. X             ptlist[numpts].x=center.x-y;   ptlist[numpts++].y=center.y-x;
  173. X   
  174. X             if (error < 0)
  175. X                error = error + (x << 2) + 6;
  176. X             else
  177. X                error = error + ((x-y--) << 2) + 10;
  178. X             x++;
  179. X           }  /* end of while (x , y) */
  180. X   
  181. X           if (x == y)
  182. X           {
  183. X             ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y+y;
  184. X             ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y+y;
  185. X             ptlist[numpts].x=center.x+x;   ptlist[numpts++].y=center.y-y;
  186. X             ptlist[numpts].x=center.x-x;   ptlist[numpts++].y=center.y-y;
  187. X           }
  188. X
  189. X       my_pw_polypoint(pw,0,0,numpts,ptlist,PIX_SET);
  190. X}  /* end of function draw_circle() */   
  191. X
  192. X
  193. X
  194. Xmy_pw_polypoint(temp_pw,off_x,off_y,count_pts,ptlist, ROP)
  195. XPixwin *temp_pw;
  196. Xint off_x,off_y,count_pts;
  197. Xstruct pr_pos ptlist[];
  198. Xint ROP;
  199. X{
  200. X
  201. X  if (image_depth > 1)
  202. X  {
  203. X    while(--count_pts > 0)
  204. X    {
  205. X      pw_rop(temp_pw,off_x+ptlist[count_pts].x,off_y+ptlist[count_pts].y,1,1
  206. X      ,PIX_COLOR(cur_color) | PIX_SRC ,pattern[0],0,0);
  207. X    }
  208. X  }
  209. X  else
  210. X  {
  211. X    pw_polypoint(temp_pw,off_x,off_y,count_pts,ptlist,ROP);
  212. X  }
  213. X}
  214. END_OF_circle.c
  215. if test 3577 -ne `wc -c <circle.c`; then
  216.     echo shar: \"circle.c\" unpacked with wrong size!
  217. fi
  218. # end of overwriting check
  219. fi
  220. if test -f cms_rainbow.c -a "${1}" != "-c" ; then 
  221.   echo shar: Will not over-write existing file \"cms_rainbow.c\"
  222. else
  223. echo shar: Extracting \"cms_rainbow.c\" \(2886 characters\)
  224. sed "s/^X//" >cms_rainbow.c <<'END_OF_cms_rainbow.c'
  225. X
  226. X/**************************************************************************
  227. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  228. X   Copyright (c) 1988 by Raymond Kreisel
  229. X   1/22/88 @ Suny Stony Brook
  230. X
  231. X   This program may be redistributed without fee as long as this copyright
  232. X   notice is intact.
  233. X
  234. X==> PLEASE send comments and bug reports to one of the following addresses:
  235. X
  236. X       Ray Kreisel
  237. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  238. X
  239. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  240. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  241. X       CSnet: rayk@suny-sb
  242. X       (If nobody is home at any of the above addresses try:
  243. X        S72QKRE@TOWSONVX.BITNET                    )
  244. X
  245. X "If I get home before daylight, I just might get some sleep tonight...."
  246. X
  247. X**************************************************************************/
  248. X/**************************************************************************
  249. X    file:  cms_rainbow.c
  250. X    purpose: this file contains that funciton that initalizes the
  251. X        the default color table for color sun usage
  252. X
  253. X    modifications:
  254. X        date:    Tue Mar 22 22:04:58 EST 1988
  255. X        author:    rayk
  256. X        changes:add comments
  257. X**************************************************************************/
  258. X
  259. Xextern unsigned char red[256],green[256],blue[256];
  260. X
  261. Xset_colorentry(i, r, g, b)
  262. X{
  263. X  red[i] =r;
  264. X  green[i] =g;
  265. X  blue[i]=b;
  266. X}
  267. X
  268. X
  269. X
  270. Xvoid init_colortable()
  271. X
  272. X{
  273. X    int i, red, green, blue;
  274. X    set_colorentry(0, 255, 255, 255);    /* white */
  275. X    set_colorentry(1, 0, 0, 0);        /* black */
  276. X    red = blue = green = 0;
  277. X
  278. X    for (i = 2; i < 30; i++) {
  279. X    red += 9;
  280. X    set_colorentry(i, red, green, blue);
  281. X    }
  282. X    set_colorentry(30, 255, 0, 0);    /* red */
  283. X    red = 255; blue = green = 0;
  284. X    for (i = 30; i < 62; i++) {
  285. X    green += 6;
  286. X    set_colorentry(i, red, green, blue);
  287. X    }
  288. X    set_colorentry(62, 255, 195, 0);    /* orange */ /* note diff = 33 */
  289. X    red = 255; blue = 0; green = 195;
  290. X    for (i = 63; i < 96; i++) {
  291. X    green += 2;
  292. X    set_colorentry(i, red, green, blue);
  293. X    }
  294. X    set_colorentry(96, 255, 255, 0);    /* yellow */
  295. X    red = 255; blue = 0; green = 255;
  296. X    for (i = 97; i < 133; i++) {
  297. X    red -= 7;
  298. X    set_colorentry(i, red, green, blue);
  299. X    }
  300. X    set_colorentry(133, 0, 255, 0);    /* green */
  301. X    red = blue = 0; green = 255;
  302. X    for (i = 134; i < 165; i++) {
  303. X    green -= 8;
  304. X    blue += 8;
  305. X    set_colorentry(i, red, green, blue);
  306. X    }
  307. X    set_colorentry(165, 0, 0, 255);    /* blue */
  308. X    red = green = 0; blue = 255;
  309. X    for (i = 165; i < 202; i++) {
  310. X    red += 7;
  311. X    set_colorentry(i, red, green, blue);
  312. X    }
  313. X    set_colorentry(202, 255, 0, 255);    /* violet */
  314. X    red = blue = 255; green = 0;
  315. X    for (i = 203; i < 239; i++) {
  316. X    green += 7;
  317. X    set_colorentry(i, red, green, blue);
  318. X    }
  319. X    set_colorentry(239, 255, 255, 255);    /* white */
  320. X    red = blue = green = 255;
  321. X    for (i = 239; i <= 255; i++) {
  322. X    green -= 9;
  323. X    red -= 9;
  324. X    blue -= 9;
  325. X    set_colorentry(i, red, green, blue);
  326. X    }
  327. X}
  328. X
  329. END_OF_cms_rainbow.c
  330. if test 2886 -ne `wc -c <cms_rainbow.c`; then
  331.     echo shar: \"cms_rainbow.c\" unpacked with wrong size!
  332. fi
  333. # end of overwriting check
  334. fi
  335. if test -f color_palet.c -a "${1}" != "-c" ; then 
  336.   echo shar: Will not over-write existing file \"color_palet.c\"
  337. else
  338. echo shar: Extracting \"color_palet.c\" \(4455 characters\)
  339. sed "s/^X//" >color_palet.c <<'END_OF_color_palet.c'
  340. X
  341. X/**************************************************************************
  342. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  343. X   Copyright (c) 1988 by Raymond Kreisel
  344. X   1/22/88 @ Suny Stony Brook
  345. X
  346. X   This program may be redistributed without fee as long as this copyright
  347. X   notice is intact.
  348. X
  349. X==> PLEASE send comments and bug reports to one of the following addresses:
  350. X
  351. X       Ray Kreisel
  352. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  353. X
  354. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  355. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  356. X       CSnet: rayk@suny-sb
  357. X       (If nobody is home at any of the above addresses try:
  358. X        S72QKRE@TOWSONVX.BITNET                    )
  359. X
  360. X "If I get home before daylight, I just might get some sleep tonight...."
  361. X
  362. X**************************************************************************/
  363. X/**************************************************************************
  364. X    file:color_palet.c
  365. X    purpose: This file contains that functions that handle the color
  366. X        map for usage with color suns
  367. X
  368. X    modifications:
  369. X        date:    Tue Mar 22 22:04:58 EST 1988
  370. X        author:    rayk
  371. X        changes:add comments
  372. X**************************************************************************/
  373. X
  374. X#include "header.h"
  375. X#include <sunwindow/cms_mono.h>
  376. X
  377. X/*
  378. X * Lets go into color mode, scotty
  379. X *
  380. X */
  381. Xset_color()
  382. X{
  383. X  panel_set(mono_cycle,PANEL_SHOW_ITEM, FALSE,0);
  384. X  panel_set(color_button,PANEL_SHOW_ITEM, TRUE,0);
  385. X}
  386. X
  387. X
  388. X/*
  389. X * Back to mono mode
  390. X *
  391. X */
  392. Xset_mono()
  393. X{
  394. X/* set the color map to mono ******** */
  395. X  cms_monochromeload(red,green,blue);
  396. X  my_put_colormap();
  397. X  panel_set(color_button,PANEL_SHOW_ITEM, FALSE,0);
  398. X  panel_set(mono_cycle,PANEL_SHOW_ITEM, TRUE,0);
  399. X}
  400. X
  401. X/*
  402. X * Set the colormap for all of the windows
  403. X */
  404. Xunsigned char temp_red[256],temp_green[256],temp_blue[256];
  405. X
  406. Xmy_put_colormap()
  407. X{
  408. XPixwin *temp_pw;
  409. X
  410. X  pw_setcmsname(pw, "ray kreisel");
  411. X  pw_putcolormap(pw, 0,256,red,green,blue);
  412. X  pw_setcmsname(fat_pw, "ray kreisel");
  413. X  pw_putcolormap(fat_pw, 0,256,red,green,blue);
  414. X  pw_setcmsname(color_pw, "ray kreisel");
  415. X  pw_putcolormap(color_pw, 0,256,red,green,blue);
  416. X
  417. X  bcopy(red,temp_red,256);
  418. X  bcopy(green,temp_green,256);
  419. X  bcopy(blue,temp_blue,256);
  420. X  temp_red[0] = -1;
  421. X  temp_green[0] = -1;
  422. X  temp_blue[0] = -1;
  423. X  temp_red[1] = 0;
  424. X  temp_green[1] = 0;
  425. X  temp_blue[1] = 0;
  426. X
  427. X  temp_pw = (Pixwin *)window_get(panel, WIN_PIXWIN);
  428. X  pw_setcmsname(temp_pw, "ray kreisel");
  429. X  pw_putcolormap(temp_pw, 0,256,red,green,blue);
  430. X
  431. X  temp_pw = (Pixwin *)window_get(command_panel, WIN_PIXWIN);
  432. X  pw_setcmsname(temp_pw, "ray kreisel");
  433. X  pw_putcolormap(temp_pw, 0,256,red,green,blue);
  434. X
  435. X  temp_pw = (Pixwin *)window_get(region_panel, WIN_PIXWIN);
  436. X  pw_setcmsname(temp_pw, "ray kreisel");
  437. X  pw_putcolormap(temp_pw, 0,256,red,green,blue);
  438. X
  439. X  temp_pw = (Pixwin *)window_get(pattern_panel, WIN_PIXWIN);
  440. X  pw_setcmsname(temp_pw, "ray kreisel");
  441. X  pw_putcolormap(temp_pw, 0,256,red,green,blue);
  442. X
  443. X  temp_pw = (Pixwin *)window_get(brush_panel, WIN_PIXWIN);
  444. X  pw_setcmsname(temp_pw, "ray kreisel");
  445. X  pw_putcolormap(temp_pw, 0,256,red,green,blue);
  446. X
  447. X}
  448. X
  449. Xcolor_mode(item, event)
  450. XPanel_item      item;
  451. XEvent           *event;
  452. X{
  453. X    (void)window_set(color_frame, WIN_SHOW, TRUE, 0);
  454. X    draw_colormap();
  455. X}
  456. X
  457. X
  458. X/*
  459. X * Draw the colormap up on a canvas in the color palet window
  460. X */
  461. Xdraw_colormap()
  462. X{
  463. Xint i;
  464. X  for (i=0;i<256;i++)
  465. X    pw_write(color_pw,(i%16)*PALET_BLOCK,i/16*PALET_BLOCK,PALET_BLOCK,PALET_BLOCK,PIX_COLOR(i) | PIX_SRC,NILPR,0,0);
  466. X  update_cur_color(0,0,cur_color);
  467. X}
  468. X
  469. X
  470. X
  471. X/*
  472. X * Get rid of the color palet
  473. X */
  474. Xcolor_done(item, event)
  475. XPanel_item      item;
  476. XEvent           *event;
  477. X{
  478. X    (void)window_set(color_frame, WIN_SHOW, FALSE, 0);
  479. X}
  480. X
  481. X
  482. X/*
  483. X * Make an event handle for the mouse envent of the color palet
  484. X * Let the use pick a block on the color palet and set the current
  485. X * color a cordingly
  486. X */
  487. Xcolor_handle_event(canvas_local, event, arg)
  488. XCanvas  canvas_local;
  489. XEvent   *event;
  490. Xcaddr_t arg;
  491. X{
  492. X    if (event_is_up(event))
  493. X       return;
  494. X    switch (event_id(event)) {
  495. X     case MS_LEFT:
  496. X        update_cur_color(event_x(event),event_y(event),0);
  497. X        break;
  498. X    }
  499. X}
  500. X
  501. X
  502. X/*
  503. X * Redraw the currrent color at the bottom of the color palet
  504. X */
  505. Xupdate_cur_color(x,y,value)
  506. X{
  507. X  if (value)
  508. X   {
  509. X    cur_color= value;
  510. X   }
  511. X  else
  512. X   {
  513. X     if ((x >= PALET_BLOCK*16) || (y >= PALET_BLOCK*16))
  514. X       return(0);
  515. X     cur_color = x/PALET_BLOCK + y/PALET_BLOCK*16;
  516. X   }
  517. X  pw_write(color_pw,0,PALET_BLOCK*16+8,PALET_BLOCK*16,PALET_BLOCK*2,PIX_COLOR(cur_color) | PIX_SRC,NILPR,0,0);
  518. X}
  519. X
  520. END_OF_color_palet.c
  521. if test 4455 -ne `wc -c <color_palet.c`; then
  522.     echo shar: \"color_palet.c\" unpacked with wrong size!
  523. fi
  524. # end of overwriting check
  525. fi
  526. if test -f command.c -a "${1}" != "-c" ; then 
  527.   echo shar: Will not over-write existing file \"command.c\"
  528. else
  529. echo shar: Extracting \"command.c\" \(4366 characters\)
  530. sed "s/^X//" >command.c <<'END_OF_command.c'
  531. X
  532. X/**************************************************************************
  533. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  534. X   Copyright (c) 1988 by Raymond Kreisel
  535. X   1/22/88 @ Suny Stony Brook
  536. X
  537. X   This program may be redistributed without fee as long as this copyright
  538. X   notice is intact.
  539. X
  540. X==> PLEASE send comments and bug reports to one of the following addresses:
  541. X
  542. X       Ray Kreisel
  543. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  544. X
  545. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  546. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  547. X       CSnet: rayk@suny-sb
  548. X       (If nobody is home at any of the above addresses try:
  549. X        S72QKRE@TOWSONVX.BITNET                    )
  550. X
  551. X "If I get home before daylight, I just might get some sleep tonight...."
  552. X
  553. X**************************************************************************/
  554. X
  555. X/**************************************************************************
  556. X    file: command.c
  557. X    purpose: This file contains the icon data for the command icons
  558. X        in the command menu of the righthand side of the main window
  559. X
  560. X    modifications:
  561. X        date:    Tue Mar 22 22:04:58 EST 1988
  562. X        author:    rayk
  563. X        changes:add comments
  564. X**************************************************************************/
  565. X#include <pixrect/pixrect_hs.h>
  566. X
  567. X
  568. Xstatic short command1_data[] = {
  569. X#include "laso.cicon.pat"
  570. X};
  571. Xstatic mpr_static(command1_pr, 48, 48, 1, command1_data);
  572. X
  573. Xstatic short command2_data[] = {
  574. X#include "circle_h.cicon.pat"
  575. X};
  576. Xstatic mpr_static(command2_pr, 48, 48, 1, command2_data);
  577. X
  578. Xstatic short command3_data[] = {
  579. X#include "draw.cicon.pat"
  580. X};
  581. Xstatic mpr_static(command3_pr, 48, 48, 1, command3_data);
  582. X
  583. Xstatic short command4_data[] = {
  584. X#include "line.cicon.pat"
  585. X};
  586. Xstatic mpr_static(command4_pr, 48, 48, 1, command4_data);
  587. X
  588. Xstatic short command5_data[] = {
  589. X#include "mag.cicon.pat"
  590. X};
  591. Xstatic mpr_static(command5_pr, 48, 48, 1, command5_data);
  592. X
  593. Xstatic short command6_data[] = {
  594. X#include "ffill.cicon.pat"
  595. X};
  596. Xstatic mpr_static(command6_pr, 48, 48, 1, command6_data);
  597. X
  598. Xstatic short command7_data[] = {
  599. X#include "oval_h.cicon.pat"
  600. X};
  601. Xstatic mpr_static(command7_pr, 48, 48, 1, command7_data);
  602. X
  603. Xstatic short command8_data[] = {
  604. X#include "poly_f.cicon.pat"
  605. X};
  606. Xstatic mpr_static(command8_pr, 48, 48, 1, command8_data);
  607. X
  608. Xstatic short command9_data[] = {
  609. X#include "poly_h.cicon.pat"
  610. X};
  611. Xstatic mpr_static(command9_pr, 48, 48, 1, command9_data);
  612. X
  613. Xstatic short command10_data[] = {
  614. X#include "rectan_f.cicon.pat"
  615. X};
  616. Xstatic mpr_static(command10_pr, 48, 48, 1, command10_data);
  617. X
  618. Xstatic short command11_data[] = {
  619. X#include "rectan_h.cicon.pat"
  620. X};
  621. Xstatic mpr_static(command11_pr, 48, 48, 1, command11_data);
  622. X
  623. Xstatic short command12_data[] = {
  624. X#include "text.cicon.pat"
  625. X};
  626. Xstatic mpr_static(command12_pr, 48, 48, 1, command12_data);
  627. X
  628. Xstatic short command13_data[] = {
  629. X#include "sel_reg.cicon.pat"
  630. X};
  631. Xstatic mpr_static(command13_pr, 48, 48, 1, command13_data);
  632. X
  633. Xstatic short command14_data[] = {
  634. X#include "sel_point.cicon.pat"
  635. X};
  636. Xstatic mpr_static(command14_pr, 48, 48, 1, command14_data);
  637. X
  638. Xstatic short command15_data[] = {
  639. X#include "paint.cicon.pat"
  640. X};
  641. Xstatic mpr_static(command15_pr, 48, 48, 1, command15_data);
  642. X
  643. Xstatic short command16_data[] = {
  644. X#include "erase.cicon.pat"
  645. X};
  646. Xstatic mpr_static(command16_pr, 48, 48, 1, command16_data);
  647. X
  648. X/* SELECTED REGION COMMANDS */
  649. X
  650. Xstatic short reg_command1_data[] = {
  651. X#include "cut.cicon.pat"
  652. X};
  653. Xstatic mpr_static(reg_command1_pr, 48, 48, 1, reg_command1_data);
  654. X
  655. Xstatic short reg_command2_data[] = {
  656. X#include "flip_hor.cicon.pat"
  657. X};
  658. Xstatic mpr_static(reg_command2_pr, 48, 48, 1, reg_command2_data);
  659. X
  660. Xstatic short reg_command3_data[] = {
  661. X#include "flip_ver.cicon.pat"
  662. X};
  663. Xstatic mpr_static(reg_command3_pr, 48, 48, 1, reg_command3_data);
  664. X
  665. Xstatic short reg_command4_data[] = {
  666. X#include "inverse.cicon.pat"
  667. X};
  668. Xstatic mpr_static(reg_command4_pr, 48, 48, 1, reg_command4_data);
  669. X
  670. Xstatic short reg_command5_data[] = {
  671. X#include "copy.cicon.pat"
  672. X};
  673. Xstatic mpr_static(reg_command5_pr, 48, 48, 1, reg_command5_data);
  674. X
  675. Xstatic short reg_command6_data[] = {
  676. X#include "paste.cicon.pat"
  677. X};
  678. Xstatic mpr_static(reg_command6_pr, 48, 48, 1, reg_command6_data);
  679. X
  680. Xstatic short reg_command7_data[] = {
  681. X#include "rotate.cicon.pat"
  682. X};
  683. Xstatic mpr_static(reg_command7_pr, 48, 48, 1, reg_command7_data);
  684. X
  685. X
  686. Xstatic short reg_command8_data[] = {
  687. X#include "move.cicon.pat"
  688. X};
  689. Xstatic mpr_static(reg_command8_pr, 48, 48, 1, reg_command8_data);
  690. END_OF_command.c
  691. if test 4366 -ne `wc -c <command.c`; then
  692.     echo shar: \"command.c\" unpacked with wrong size!
  693. fi
  694. # end of overwriting check
  695. fi
  696. if test -f confirmer.c -a "${1}" != "-c" ; then 
  697.   echo shar: Will not over-write existing file \"confirmer.c\"
  698. else
  699. echo shar: Extracting \"confirmer.c\" \(4328 characters\)
  700. sed "s/^X//" >confirmer.c <<'END_OF_confirmer.c'
  701. X
  702. X/**************************************************************************
  703. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  704. X   Copyright (c) 1988 by Raymond Kreisel
  705. X   1/22/88 @ Suny Stony Brook
  706. X
  707. X   This program may be redistributed without fee as long as this copyright
  708. X   notice is intact.
  709. X
  710. X==> PLEASE send comments and bug reports to one of the following addresses:
  711. X
  712. X       Ray Kreisel
  713. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  714. X
  715. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  716. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  717. X       CSnet: rayk@suny-sb
  718. X
  719. X "If I get home before daylight, I just might get some sleep tonight...."
  720. X
  721. X**************************************************************************/
  722. X/**************************************************************************
  723. X    file: confirmer.c
  724. X    purpose: This file contains a simple confirmer copied from the
  725. X     Sunview manual that has been souped up a little
  726. X
  727. X    modifications:
  728. X        date:    Tue Mar 22 22:04:58 EST 1988
  729. X        author:    rayk
  730. X        changes:add comments
  731. X**************************************************************************/
  732. X
  733. X#include <stdio.h>
  734. X#include <sys/file.h>
  735. X#include <suntool/sunview.h>
  736. X#include <suntool/panel.h>
  737. X#include <suntool/canvas.h>
  738. X#include <suntool/walkmenu.h>
  739. X#include <suntool/scrollbar.h>
  740. X#include <math.h>
  741. X#include <pixrect/pixrect_hs.h>
  742. X
  743. Xextern Panel panel;
  744. X
  745. Xstatic Frame  init_confirmer();
  746. Xstatic void yes_no();
  747. X
  748. X/***************************************************************
  749. X        confirm
  750. X        purpose: To display a window on the base_frame Sunwindow
  751. X                force the user to answer the question by selecting
  752. X        either YES or NO
  753. X        parameter:
  754. X                message: The question to asked.
  755. X        returns:
  756. X        1 : if the user answered YES
  757. X        0 : if the user answered NO
  758. X ***************************************************************/
  759. Xint confirm(message)
  760. Xchar     *message; 
  761. X{
  762. X    Frame     confirmer;
  763. X    int       answer;
  764. X
  765. X/* create the confirmer */
  766. X    confirmer = init_confirmer(message);
  767. X    window_bell(panel);
  768. X/* make the user answer */
  769. X     answer = (int) window_loop(confirmer);
  770. X
  771. X/* destroy the confirmer */
  772. X    window_set(confirmer, FRAME_NO_CONFIRM, TRUE, 0);
  773. X    window_destroy(confirmer);
  774. X
  775. X        return answer;
  776. X}
  777. X
  778. Xstatic Frame
  779. Xinit_confirmer(message)
  780. Xchar     *message; 
  781. X{ 
  782. Xextern   Frame  base_frame;
  783. XFrame           confirmer;
  784. XPanel           panel;
  785. XPanel_item      message_item;
  786. Xint             left, top, width, height;
  787. XRect            *r;
  788. Xstruct pixrect  *pr;
  789. X
  790. X/* create the confirmer base frame */
  791. X    confirmer = window_create(base_frame, FRAME, 
  792. X                                  FRAME_SHOW_LABEL, FALSE,
  793. X                  0);
  794. X
  795. X/* create the single panel subwindow */
  796. X    panel = window_create(confirmer, PANEL, 0);
  797. X
  798. X/* put in the message */
  799. X    message_item = panel_create_item(panel, PANEL_MESSAGE,
  800. X                    PANEL_LABEL_STRING, message,
  801. X                    0);
  802. X
  803. X    pr = panel_button_image(panel, "NO", 3, 0);
  804. X    width = 2 * pr->pr_width + 10;
  805. X
  806. X      r = (Rect *) panel_get(message_item, PANEL_ITEM_RECT);
  807. X
  808. X/* center the yes/no buttons under the message */
  809. X    left = (r->r_width - width) / 2;
  810. X    if (left < 0)
  811. X        left = 0;
  812. X    top = rect_bottom(r) + 5;
  813. X
  814. X        panel_create_item(panel, PANEL_BUTTON,
  815. X                  PANEL_ITEM_X, left,
  816. X              PANEL_ITEM_Y, top,
  817. X              PANEL_LABEL_IMAGE, pr,
  818. X              PANEL_CLIENT_DATA, FALSE,
  819. X          PANEL_NOTIFY_PROC, yes_no,
  820. X          0);
  821. X        panel_create_item(panel, PANEL_BUTTON,
  822. X              PANEL_LABEL_IMAGE, panel_button_image(panel, "YES", 3, 0),
  823. X              PANEL_CLIENT_DATA, TRUE,
  824. X          PANEL_NOTIFY_PROC, yes_no,
  825. X          0);
  826. X
  827. X    window_fit(panel);
  828. X    window_fit(confirmer);
  829. X
  830. X/* center the confirmer frame in the base frame */
  831. X    r = (Rect *) window_get(base_frame, WIN_RECT);
  832. X
  833. X    width = (int) window_get(confirmer, WIN_WIDTH);
  834. X    height = (int) window_get(confirmer, WIN_HEIGHT);
  835. X
  836. X    left = (r->r_width - width) / 2;
  837. X    top = (r->r_height - height) / 3;
  838. X
  839. X        if (left < 0) 
  840. X            left = 0; 
  841. X     if (top < 0)
  842. X        top = 0;
  843. X
  844. X    window_set(confirmer, WIN_X, left, WIN_Y, top,
  845. X            0);
  846. X
  847. X        left = left + (width - width/3);
  848. X        top = top + height / 2;      
  849. X    window_set(base_frame, WIN_MOUSE_XY, left, top,  0);
  850. X
  851. X    return confirmer;
  852. X}
  853. X
  854. X/* yes/no notify proc */
  855. Xstatic void
  856. Xyes_no(item, event)
  857. XPanel_item   item;
  858. XEvent        *event;
  859. X{
  860. X    window_return(panel_get(item, PANEL_CLIENT_DATA));
  861. X}
  862. X
  863. END_OF_confirmer.c
  864. if test 4328 -ne `wc -c <confirmer.c`; then
  865.     echo shar: \"confirmer.c\" unpacked with wrong size!
  866. fi
  867. # end of overwriting check
  868. fi
  869. if test -f disk_io.c -a "${1}" != "-c" ; then 
  870.   echo shar: Will not over-write existing file \"disk_io.c\"
  871. else
  872. echo shar: Extracting \"disk_io.c\" \(14884 characters\)
  873. sed "s/^X//" >disk_io.c <<'END_OF_disk_io.c'
  874. X
  875. X/**************************************************************************
  876. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  877. X   Copyright (c) 1988 by Raymond Kreisel
  878. X   1/22/88 @ Suny Stony Brook
  879. X
  880. X   This program may be redistributed without fee as long as this copyright
  881. X   notice is intact.
  882. X
  883. X==> PLEASE send comments and bug reports to one of the following addresses:
  884. X
  885. X       Ray Kreisel
  886. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  887. X
  888. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  889. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  890. X       CSnet: rayk@suny-sb
  891. X       (If nobody is home at any of the above addresses try:
  892. X        S72QKRE@TOWSONVX.BITNET                    )
  893. X
  894. X "If I get home before daylight, I just might get some sleep tonight...."
  895. X
  896. X**************************************************************************/
  897. X/**************************************************************************
  898. X    file: disk_io.c
  899. X    purpose: This file handle most of the file I/O stuff
  900. X      mostly load, save and file completion
  901. X
  902. X    modifications:
  903. X        date:    Tue Mar 22 22:04:58 EST 1988
  904. X        author:    rayk
  905. X        changes:add comments
  906. X**************************************************************************/
  907. X
  908. X#include "header.h"
  909. X
  910. X#include <sys/types.h>
  911. X#include <sys/dir.h>
  912. X#include <sys/file.h>
  913. X#include <pwd.h>
  914. X
  915. Xcolormap_t colormap;
  916. X
  917. X/*
  918. X * Let's do file completion on what we have in the file name prompt
  919. X */
  920. Xmake_new_name(item, event)
  921. XPanel_item      item;
  922. XEvent           *event;
  923. X{
  924. X  strcpy(file_name,(char*)panel_get_value(file_panel));
  925. X  if (complete(file_name))
  926. X      window_bell(panel);
  927. X  panel_set(file_panel,PANEL_VALUE,file_name,0);
  928. X}
  929. X
  930. X
  931. X/* This function, written by Marc J Newberger,
  932. X * will do both login name completion and file name completion, DAM fast.
  933. X * That means as fast as the csh does it.
  934. X */
  935. Xint complete(template)
  936. X
  937. X    char    *template;
  938. X
  939. X{
  940. X
  941. X    char    dirName[255];
  942. X    char   *prefix;    
  943. X    int     pref_len;
  944. X    char   *suffix;     
  945. X    char   *p, *q;
  946. X    char    first;
  947. X    char    nonUnique;
  948. X    char    twiddleUserCompletion;
  949. X
  950. X    extern  int         errno;
  951. X    struct  direct     *nameEntry;
  952. X    DIR                *dirChan;
  953. X    struct  passwd     *pwdEntry;
  954. X
  955. X    /*
  956. X     *  First do a little parsing of the input. Separate the
  957. X     *  prefix template from the directory if there is one.
  958. X     */
  959. X    twiddleUserCompletion= 0;
  960. X    prefix= template+strlen(template);
  961. X    while (*(--prefix) != '/' && prefix >= template);
  962. X
  963. X    /*
  964. X     *  See if a directory was specified:
  965. X     */
  966. X    if (prefix < template) {
  967. X        /*
  968. X         *  No /'s, could be either a username completion or
  969. X         *  a completion in the current directory.
  970. X         */
  971. X        if (template[0] == '~') {
  972. X            prefix++;
  973. X            twiddleUserCompletion= 1;
  974. X            }
  975. X        else {
  976. X            strcpy(dirName, ".");
  977. X            }
  978. X        }
  979. X    else if (prefix == template) {
  980. X        /*
  981. X         *  Special case !! The directory excluding the trailing
  982. X         *  '/' is zero length. It's the root:
  983. X         */
  984. X        strcpy(dirName, "/");
  985. X        }
  986. X    else {
  987. X        /*
  988. X         *  We're completing a file in a directory.
  989. X         *  The directory may be lead by a ~<username> abbreviation.
  990. X         *  If that's the case expand it.
  991. X         */
  992. X        if (template[0] == '~') {
  993. X            /*
  994. X             *  We need to do twiddle directory expansion.
  995. X             *  See if it's our directory:
  996. X             */
  997. X            if (template[1] == '/') {
  998. X                strcpy(dirName, getenv("HOME"));
  999. X        if ( &template[1] != prefix )
  1000. X          {
  1001. X                    p= dirName+strlen(dirName);
  1002. X                q= &template[1];
  1003. X                    while (q < prefix) {
  1004. X                        *p= *q;
  1005. X                        p++, q++;
  1006. X                        }
  1007. X                    *p= 0;
  1008. X          }
  1009. X                }
  1010. X            else {
  1011. X                /*
  1012. X                 * It's someone else's. Let our fingers
  1013. X                 * do the walking. (Why the fuck do they call it
  1014. X                 * the "yellow pages" anyway. They're white pages
  1015. X                 * dammit !  If they were YELLOW pages, we could
  1016. X                 * say ypmatch "Automobile, Dealers, Retail", and
  1017. X                 * things like that !).
  1018. X                 */
  1019. X                for (p= dirName, q= &template[1];
  1020. X                        (*p= *q) != '/';
  1021. X                            p++, q++);
  1022. X                *p= 0;
  1023. X                if (!(pwdEntry= getpwnam(dirName))) {
  1024. X                    return errno;
  1025. X                    }
  1026. X                strcpy(dirName, pwdEntry->pw_dir);
  1027. X                p= dirName+strlen(dirName);
  1028. X                while (q < prefix) {
  1029. X                    *p= *q;
  1030. X                    p++, q++;
  1031. X                    }
  1032. X                *p= 0;
  1033. X                }
  1034. X            }
  1035. X        else {
  1036. X            /*
  1037. X             *  It's a vanilla directory. Strip it out.
  1038. X             */
  1039. X            strncpy(dirName, template, prefix-template);
  1040. X            dirName[prefix-template]= 0;
  1041. X            }
  1042. X        }
  1043. X    /*
  1044. X     *  Bump prefix past the '/'.
  1045. X     */
  1046. X    prefix++;
  1047. X
  1048. X    /*
  1049. X     *  Get the prefix length and a pointer to the end of the
  1050. X     *  prefix.
  1051. X     */
  1052. X    pref_len= strlen(prefix);
  1053. X    suffix= template + strlen(template);
  1054. X
  1055. X    /*
  1056. X     *  See whether we're doing filename or username completion:
  1057. X     */
  1058. X    if (!twiddleUserCompletion) {
  1059. X
  1060. X        /*
  1061. X         *  It's filename completion. Read through the directory:
  1062. X         */
  1063. X        if ((dirChan= opendir(dirName)) == 0) {
  1064. X            return errno;
  1065. X            }
  1066. X
  1067. X        first= 1;
  1068. X        nonUnique= 0;
  1069. X        for (;;) {
  1070. X            if (!(nameEntry= readdir(dirChan))) {
  1071. X                break;
  1072. X                }
  1073. X            if (!strncmp(prefix, nameEntry->d_name, pref_len)) {
  1074. X                /*
  1075. X                 *  We have a file that matches the template.
  1076. X                 *  If it's the first one, we fill the completion
  1077. X                 *  suffix with it. Otherwise we scan and pare down
  1078. X                 *  the suffix.
  1079. X                 */
  1080. X                if (first) {
  1081. X                    first=  0 ;
  1082. X                    strcpy(suffix, nameEntry->d_name+pref_len);
  1083. X                    }
  1084. X                else {
  1085. X                    nonUnique= 1;
  1086. X                    p= suffix;
  1087. X                    q= nameEntry->d_name+pref_len;
  1088. X                    while (*p == *q) {
  1089. X                        ++p; ++q;
  1090. X                        }
  1091. X                    *p= 0;
  1092. X
  1093. X                    /*
  1094. X                     *  A little optimization: If p == suffix, we
  1095. X                     *  were unable to do any extension of the name.
  1096. X                     *  We might as well quit here.
  1097. X                     */
  1098. X                    if (p == suffix) {
  1099. X                        break;
  1100. X                        }
  1101. X                    }
  1102. X                }
  1103. X            }
  1104. X
  1105. X        closedir(dirChan);
  1106. X        }
  1107. X    else {
  1108. X        /*
  1109. X         *  Do ~Username completion. Start by resetting the passwd file.
  1110. X         */
  1111. X        setpwent();
  1112. X
  1113. X        first= 1;
  1114. X        nonUnique= 0;
  1115. X        for (;;) {
  1116. X            if (!(pwdEntry= getpwent())) {
  1117. X                break;
  1118. X                }
  1119. X            if (!strncmp(prefix, pwdEntry->pw_name, pref_len)) {
  1120. X                /*
  1121. X                 *  We have a user that matches the template.
  1122. X                 *  If it's the first one, we fill the completion
  1123. X                 *  suffix with it. Otherwise we scan and pare down
  1124. X                 *  the suffix.
  1125. X                 */
  1126. X                if (first) {
  1127. X                    first=  0 ;
  1128. X                    strcpy(suffix, pwdEntry->pw_name+pref_len);
  1129. X                    }
  1130. X                else {
  1131. X                    p= suffix;
  1132. X                    q= pwdEntry->pw_name+pref_len;
  1133. X                    while (*p == *q) {
  1134. X                        ++p; ++q;
  1135. X                        }
  1136. X
  1137. X                    /*
  1138. X                     *  Here there is a possibility of seeing the
  1139. X                     *  same username twice. For this reason, we
  1140. X                     *  only set nonUnique to 1 if we're shortening
  1141. X                     *  the suffix. This means that the new name is
  1142. X                     *  distinct from any name we've seen.
  1143. X                     */
  1144. X                    if (*p) {
  1145. X                        nonUnique= 1;
  1146. X                        *p= 0;
  1147. X                        }
  1148. X
  1149. X                    /*
  1150. X                     *  A little optimization: If p == suffix, we
  1151. X                     *  were unable to do any extension of the name.
  1152. X                     *  We might as well quit here.
  1153. X                     */
  1154. X                    if (p == suffix) {
  1155. X                        break;
  1156. X                        }
  1157. X                    }
  1158. X                }
  1159. X            }
  1160. X        }
  1161. X
  1162. X    /*
  1163. X     *  If nothing matched, return a -1, if there was non-uniqueness
  1164. X     *  return -2.
  1165. X     */ 
  1166. X    if (first) {
  1167. X        return -1;
  1168. X        }
  1169. X    else if (nonUnique) {
  1170. X        return -2;
  1171. X        }
  1172. X    else {
  1173. X        return 0;
  1174. X        }
  1175. X
  1176. X}
  1177. X
  1178. X
  1179. X/*
  1180. X * We just got a "load" button event and we want to load in the current
  1181. X * filename.
  1182. X */
  1183. Xload_file(item, event)
  1184. XPanel_item      item;
  1185. XEvent           *event;
  1186. X{
  1187. XFILE *fp,*fopen();
  1188. Xint err=0;
  1189. Xstruct rasterfile file_header;
  1190. Xint load_area;
  1191. Xchar temp_file[MAX_FILE_NAME];
  1192. X
  1193. X  /*
  1194. X   * Copy the current filename and expand the ~ if it is there
  1195. X   */
  1196. X  strcpy(temp_file,(char*)panel_get_value(file_panel));
  1197. X  get_full_path(temp_file,file_name);
  1198. X  load_area = (int)panel_get_value(load_cycle);
  1199. X  
  1200. X  fp = fopen(file_name,"r");
  1201. X  if (fp == NULL)
  1202. X    {
  1203. X         ERRORstr("Cannot open file: ",file_name);
  1204. X     fclose(fp);
  1205. X     return(0);
  1206. X    }
  1207. X
  1208. X  /*
  1209. X   * Try to read the header of the raster file and check if it is color
  1210. X   */
  1211. X  err = pr_load_header(fp,&file_header);
  1212. X  if (file_header.ras_maplength > 3*256) err=1;
  1213. X  if (err)
  1214. X    {
  1215. X     ERROR("Cannot load the rasterfile header.");
  1216. X     fclose(fp);
  1217. X     return(0);
  1218. X    }
  1219. X
  1220. X  if (load_area == LOAD_ALL)  
  1221. X    {
  1222. X     clear_screen();
  1223. X     colormap.map[0] = red;
  1224. X     colormap.map[1] = green;
  1225. X     colormap.map[2] = blue;
  1226. X     colormap.type = file_header.ras_maptype;
  1227. X     colormap.length = file_header.ras_maplength/3;
  1228. X    }
  1229. X  /*
  1230. X   * load in the colormap for the raster file
  1231. X   */
  1232. X  if (pr_load_colormap(fp,&file_header,&colormap))
  1233. X    {
  1234. X     ERROR("Cannot load the rasterfile colormap.");    
  1235. X     fclose(fp);
  1236. X     return(0);
  1237. X    }
  1238. X  /*
  1239. X   * reset the memory pixrect and load the baby in
  1240. X   */
  1241. X  MY_pr_destroy(undo_pr);
  1242. X  undo_pr = (struct pixrect *)pr_load_image(fp,&file_header,&colormap);
  1243. X
  1244. X  if (undo_pr == NULL)
  1245. X    {
  1246. X         ERROR("Cannot allocate pixrect for loaded image file, not enough memory!");
  1247. X     fclose(fp);
  1248. X     return(0);
  1249. X    }
  1250. X
  1251. X  fclose(fp);
  1252. X
  1253. X
  1254. X  /*
  1255. X   * We are loading to the main drawing area so lets set all
  1256. X   * the color maps
  1257. X   */
  1258. X  if (load_area == LOAD_ALL)  
  1259. X    {
  1260. X     if (file_header.ras_depth > 1)
  1261. X       {
  1262. X    my_put_colormap();
  1263. X    set_color();
  1264. X       }
  1265. X     else
  1266. X       {
  1267. X        set_mono();
  1268. X        (void)window_set(canvas,
  1269. X        CANVAS_WIDTH,        file_header.ras_width,
  1270. X        CANVAS_HEIGHT,        file_header.ras_height,
  1271. X        0);
  1272. X       }
  1273. X     panel_set(save_cycle,PANEL_VALUE, SAVE_ALL,0);
  1274. X     image_wid = file_header.ras_width;
  1275. X     image_hgt = file_header.ras_height;
  1276. X     image_depth = file_header.ras_depth;
  1277. X     pw_write(pw,0,0, image_wid,image_hgt, PIX_SRC, undo_pr,0,0);
  1278. X    }
  1279. X  else
  1280. X    {
  1281. X    /*
  1282. X     * we load the image into the cut/paste buffer
  1283. X     */
  1284. X    MY_pr_destroy(cut_buffer_pr);
  1285. X    cut_buffer_pr = my_mem_create(file_header.ras_width,file_header.ras_height,file_header.ras_depth);
  1286. X    pr_rop(cut_buffer_pr,0,0,file_header.ras_width,file_header.ras_height,
  1287. X            PIX_SRC,undo_pr,0,0);
  1288. X    MY_pr_destroy(undo_pr);
  1289. X    undo_pr = my_mem_create(image_wid,image_hgt,image_depth);
  1290. X    }
  1291. X}
  1292. X
  1293. X
  1294. X
  1295. X/*
  1296. X * Save a file out out to the current filename
  1297. X *
  1298. X */
  1299. Xsave_file(item, event)
  1300. XPanel_item      item;
  1301. XEvent           *event;
  1302. X{
  1303. XFILE *fp,*fopen();
  1304. Xint type = RT_STANDARD;
  1305. Xint copy_flag = TRUE;
  1306. Xchar temp_file[MAX_FILE_NAME];
  1307. X
  1308. X /*
  1309. X  * Is the raster file to be run-length encode or not
  1310. X  */
  1311. X if((int)panel_get_value(compress_cycle))
  1312. X    type = RT_BYTE_ENCODED;
  1313. X else
  1314. X    type = RT_STANDARD;
  1315. X  
  1316. X  /*
  1317. X   * Copy the current filename and expand the ~ if it is there
  1318. X   */
  1319. X strcpy(temp_file,(char*)panel_get_value(file_panel));
  1320. X get_full_path(temp_file,file_name);
  1321. X if (file_exist(file_name))
  1322. X    {
  1323. X         if (!confirm("Over write existing file ?"))
  1324. X     return(0);
  1325. X    }
  1326. X /*
  1327. X  * dump standard SUN raster file with color table to disk file
  1328. X  */
  1329. X fp = fopen(file_name,"w");
  1330. X  if (fp == NULL)
  1331. X    {
  1332. X     fclose(fp);
  1333. X         ERRORstr("Cannot write to file: ",file_name);
  1334. X     return(0);
  1335. X    }
  1336. X /*
  1337. X  * Save the whole drawing are out to the disk file
  1338. X  */
  1339. X if (SAVE_ALL == (int)panel_get_value(save_cycle))
  1340. X   {
  1341. X     clean_point();
  1342. X     clean_region();
  1343. X     fat_done();
  1344. X     save_screen();
  1345. X
  1346. X     if (!undo_pr)
  1347. X    undo_pr = my_mem_create(image_wid,image_hgt,image_depth);
  1348. X     pr_rop(undo_pr,0,0,image_wid,image_hgt,PIX_SRC,pw->pw_prretained,0,0);
  1349. X     pr_dump(undo_pr,fp,&colormap,type,copy_flag);
  1350. X   }
  1351. X else
  1352. X   {
  1353. X  /*
  1354. X   * just save the cut/Paste buffer out to the file
  1355. X   */
  1356. X     if (cut_buffer_pr == NULL)
  1357. X    {
  1358. X     ERROR("The Cut/Paste buffer is empty");
  1359. X     fclose(fp);
  1360. X     return(0);
  1361. X    }
  1362. X     pr_dump(cut_buffer_pr,fp,&colormap,type,copy_flag);
  1363. X   }
  1364. X fclose(fp);
  1365. X}
  1366. X
  1367. X
  1368. X/*
  1369. X * Check if a file exist or not
  1370. X */
  1371. Xfile_exist(file_name)
  1372. Xchar *file_name;
  1373. X{
  1374. XFILE *fp;
  1375. X  fp = fopen(file_name,"r");
  1376. X  fclose(fp);
  1377. X  if (fp != NULL)
  1378. X    return(TRUE);
  1379. X  else
  1380. X    return(FALSE);
  1381. X}
  1382. X
  1383. X
  1384. X/*
  1385. X * Take a filename with a ~ character at the begining and return
  1386. X * the full path name to that file
  1387. X */
  1388. Xget_full_path(template,full_path)
  1389. Xchar template[];
  1390. Xchar full_path[];
  1391. X{
  1392. X    char   *p, *q;
  1393. X    struct  passwd     *pwdEntry;
  1394. X        /*
  1395. X         *  We're completing a file in a directory.
  1396. X         *  The directory may be lead by a ~<username> abbreviation.
  1397. X         *  If that's the case expand it.
  1398. X         */
  1399. X        if (template[0] == '~') {
  1400. X            /*
  1401. X             *  We need to do twiddle directory expansion.
  1402. X             *  See if it's our directory:
  1403. X             */
  1404. X            if (template[1] == '/') {
  1405. X                strcpy(full_path, getenv("HOME"));
  1406. X        strcat(full_path,&template[1]);
  1407. X                }
  1408. X            else {
  1409. X                /*
  1410. X                 * It's someone else's. Let our fingers
  1411. X                 * do the walking. (Why the fuck do they call it
  1412. X                 * the "yellow pages" anyway. They're white pages
  1413. X                 * dammit !  If they were YELLOW pages, we could
  1414. X                 * say ypmatch "Automobile, Dealers, Retail", and
  1415. X                 * things like that !).
  1416. X                 */
  1417. X                for (p= full_path, q= &template[1];
  1418. X                        (*p= *q) != '/';
  1419. X                            p++, q++);
  1420. X                *p= 0;
  1421. X                if (!(pwdEntry= getpwnam(full_path))) {
  1422. X                    return errno;
  1423. X                    }
  1424. X                strcpy(full_path, pwdEntry->pw_dir);
  1425. X        strcat(full_path,q);
  1426. X                }
  1427. X    }
  1428. X    else
  1429. X          strcpy(full_path,template);
  1430. X}         
  1431. X
  1432. END_OF_disk_io.c
  1433. if test 14884 -ne `wc -c <disk_io.c`; then
  1434.     echo shar: \"disk_io.c\" unpacked with wrong size!
  1435. fi
  1436. # end of overwriting check
  1437. fi
  1438. if test -f drawing.c -a "${1}" != "-c" ; then 
  1439.   echo shar: Will not over-write existing file \"drawing.c\"
  1440. else
  1441. echo shar: Extracting \"drawing.c\" \(16127 characters\)
  1442. sed "s/^X//" >drawing.c <<'END_OF_drawing.c'
  1443. X
  1444. X/**************************************************************************
  1445. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  1446. X   Copyright (c) 1988 by Raymond Kreisel
  1447. X   1/22/88 @ Suny Stony Brook
  1448. X
  1449. X   This program may be redistributed without fee as long as this copyright
  1450. X   notice is intact.
  1451. X
  1452. X==> PLEASE send comments and bug reports to one of the following addresses:
  1453. X
  1454. X       Ray Kreisel
  1455. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  1456. X
  1457. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  1458. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  1459. X       CSnet: rayk@suny-sb
  1460. X       (If nobody is home at any of the above addresses try:
  1461. X        S72QKRE@TOWSONVX.BITNET                    )
  1462. X
  1463. X "If I get home before daylight, I just might get some sleep tonight...."
  1464. X
  1465. X**************************************************************************/
  1466. X/**************************************************************************
  1467. X    file: drawing.c
  1468. X    purpose: This file has most of the functions that draw stuff
  1469. X    on the screen.
  1470. X
  1471. X    modifications:
  1472. X        date:    Tue Mar 22 22:04:58 EST 1988
  1473. X        author:    rayk
  1474. X        changes:add comments
  1475. X**************************************************************************/
  1476. X
  1477. X#include"header.h"
  1478. X
  1479. Xstruct pr_pos poly_points[MAX_POLY];
  1480. X
  1481. Xstruct pixrect *brush_temp_pr = NULL;
  1482. X
  1483. X/*
  1484. X * What we do that someone selects a new pattern
  1485. X */
  1486. Xselect_pattern(item, event)
  1487. XPanel_item      item;
  1488. XEvent           *event;
  1489. X{
  1490. X  panel_set(current_pattern,PANEL_LABEL_IMAGE,pattern[(int)panel_get_value(pattern_choice)],0);
  1491. X
  1492. X}
  1493. X
  1494. X
  1495. X/*
  1496. X * let the user define his own patterns to paint with
  1497. X * works for color and mono
  1498. X */
  1499. Xpattern_define(item, event)
  1500. XPanel_item      item;
  1501. XEvent           *event;
  1502. X{
  1503. X
  1504. X  if (select_pt_x == -1)
  1505. X     {
  1506. X    ERROR("Select a point first, then select Define Pattern.");
  1507. X    set_select_mode();
  1508. X    return(0);
  1509. X     }
  1510. X  select_point(select_pt_x,select_pt_y);
  1511. X  if (image_depth > 1)
  1512. X   {
  1513. X      pattern[39]  = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,image_depth);
  1514. X      pattern40_pr = *(pattern[39]);
  1515. X   }
  1516. X  pr_rop(pattern[39],0,0,PATTERN_SIZE,PATTERN_SIZE,
  1517. X        PIX_SRC,pw->pw_prretained,select_pt_x-PATTERN_SIZE/2,
  1518. X        select_pt_y-PATTERN_SIZE/2);
  1519. X
  1520. X  panel_paint(pattern_choice,PANEL_NO_CLEAR);
  1521. X  reset_point();
  1522. X  print_msg("The user defined pattern is now stored in the last pattern element.");
  1523. X}
  1524. X
  1525. X
  1526. X/*
  1527. X * Take the current text string and put that Baby up on the bitmap
  1528. X * in the right font
  1529. X */
  1530. Xdraw_text()
  1531. X{
  1532. Xint x,y;
  1533. X
  1534. X  if (select_pt_x != -1)
  1535. X    {
  1536. X      x = select_pt_x;
  1537. X      y = select_pt_y;
  1538. X      clean_point();
  1539. X      save_screen();
  1540. X      pw_text(pw,x,y,PIX_COLOR(cur_color) | PIX_SRC,font_array[(int)panel_get_value(text_size_item)],
  1541. X        (char*)panel_get_value(text_panel));
  1542. X    }
  1543. X  else
  1544. X    {
  1545. X      ERROR("Select a point first, fill in TEXT STRING, then select ABC.");
  1546. X      window_set(panel,PANEL_CARET_ITEM,text_panel,0);
  1547. X      set_select_mode();
  1548. X    }
  1549. X}
  1550. X
  1551. X
  1552. X/*
  1553. X * draw a line on the bitmap
  1554. X */
  1555. Xdraw_line(x1,y1,x2,y2,ROP,color)
  1556. Xint x1,y1,x2,y2,ROP,color;
  1557. X{
  1558. X  pw_vector(pw,x1,y1,x2,y2,ROP,color);
  1559. X}
  1560. X
  1561. X
  1562. X/*
  1563. X * draw a rectangle on the bitmap
  1564. X */
  1565. Xdraw_rectangle(x1,y1,x2,y2)
  1566. Xint x1,y1,x2,y2;
  1567. X{
  1568. X  top_x = x1;
  1569. X  top_y = y1;
  1570. X  bottom_x = x2;
  1571. X  bottom_y = y2;
  1572. X  if ((int)panel_get_value(command_choice)==RECT_F)
  1573. X    fill_region();
  1574. X  else
  1575. X    reset_region();
  1576. X  if ((int)panel_get_value(border_cycle))
  1577. X  {
  1578. X    pw_vector(pw,x1,y1,x2,y1,PIX_SRC,cur_color);
  1579. X    pw_vector(pw,x2,y1,x2,y2,PIX_SRC,cur_color);
  1580. X    pw_vector(pw,x2,y2,x1,y2,PIX_SRC,cur_color);
  1581. X    pw_vector(pw,x1,y2,x1,y1,PIX_SRC,cur_color);
  1582. X  }
  1583. X}
  1584. X
  1585. X
  1586. X/*
  1587. X * highlight the selected region on the drawing area by throwing up a
  1588. X * XORed rectangle
  1589. X */
  1590. Xselect_region(pw,x1,y1,x2,y2)
  1591. Xstruct pixwin *pw;
  1592. Xint x1,y1,x2,y2;
  1593. X{
  1594. X  pw_vector(pw,x1,y1,x2,y1,PIX_XOR,1);
  1595. X  pw_vector(pw,x2,y1,x2,y2,PIX_XOR,1);
  1596. X  pw_vector(pw,x2,y2,x1,y2,PIX_XOR,1);
  1597. X  pw_vector(pw,x1,y2,x1,y1,PIX_XOR,1);
  1598. X}
  1599. X
  1600. X
  1601. X/*
  1602. X * reset the current REGION
  1603. X */
  1604. Xreset_region()
  1605. X{
  1606. X  top_x=0;
  1607. X  top_y=0;
  1608. X  bottom_x=0;
  1609. X  bottom_y=0;
  1610. X}
  1611. X
  1612. X
  1613. X/*
  1614. X * draw up a point, how stupid ???
  1615. X */
  1616. Xdraw_point(pw,x,y)
  1617. Xstruct pixwin *pw;
  1618. Xint x,y;
  1619. X{
  1620. X  pw_put(pw,x,y,cur_color);
  1621. X}
  1622. X
  1623. X
  1624. X/*
  1625. X * Draw up the paint brush by copying the current pattern
  1626. X * through a stencil of the current brush
  1627. X */
  1628. Xdraw_brush(pw,x,y)
  1629. Xstruct pixwin *pw;
  1630. Xint x,y;
  1631. X{
  1632. X  if (brush_temp_pr == NULL)
  1633. X    brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,1);
  1634. X
  1635. X
  1636. X  if (((int)panel_get_value(pattern_choice) != 39) || (image_depth == 1))
  1637. X  {
  1638. X    if (brush_temp_pr->pr_depth != 1)
  1639. X    {
  1640. X         MY_pr_destroy(brush_temp_pr);
  1641. X        brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,1);
  1642. X    }
  1643. X    pr_replrop(brush_temp_pr,0,0,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],x,y);
  1644. X        pw_stencil(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE,PIX_COLOR(cur_color) | PIX_SRC,
  1645. X    brushes[(int)panel_get_value(brush_choice)],0,0,brush_temp_pr,0,0);
  1646. X  }
  1647. X  else
  1648. X  {
  1649. X    if (brush_temp_pr->pr_depth != image_depth)
  1650. X    {
  1651. X         MY_pr_destroy(brush_temp_pr);
  1652. X        brush_temp_pr = my_mem_create(PATTERN_SIZE,PATTERN_SIZE,image_depth);
  1653. X    }
  1654. X    pr_replrop(brush_temp_pr,0,0,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],x,y);
  1655. X        pw_stencil(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,
  1656. X    brushes[(int)panel_get_value(brush_choice)],0,0,brush_temp_pr,0,0);
  1657. X
  1658. X  }
  1659. X
  1660. X}
  1661. X
  1662. X
  1663. X/*
  1664. X * flip-flop two varibles (ints)
  1665. X */
  1666. Xswap(x,y)
  1667. Xint *x,*y;
  1668. X{
  1669. Xint temp;
  1670. X  temp = *x;
  1671. X  *x = *y;
  1672. X  *y = temp;
  1673. X}
  1674. X
  1675. X
  1676. Xregion_fix()
  1677. X{
  1678. X  if (top_x > bottom_x)
  1679. X     swap(&top_x,&bottom_x);
  1680. X  if (top_y > bottom_y)
  1681. X     swap(&top_y,&bottom_y);
  1682. X} 
  1683. X
  1684. X
  1685. X/*
  1686. X * put the eraser on the drawing area
  1687. X */
  1688. Xerase_brush(pw,x,y)
  1689. Xstruct pixwin *pw;
  1690. Xint x,y;
  1691. X{
  1692. X  select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  1693. X  pw_rop(pw,x-PATTERN_SIZE/2,y-PATTERN_SIZE/2,PATTERN_SIZE,PATTERN_SIZE, PIX_SRC,0,0,0);
  1694. X  top_x = x-PATTERN_SIZE/2; top_y= y-PATTERN_SIZE/2;
  1695. X  select_region(pw,top_x,top_y,top_x+PATTERN_SIZE,top_y+PATTERN_SIZE);
  1696. X}
  1697. X
  1698. X
  1699. X/*
  1700. X * draw up some cross hairs to be used to select a point
  1701. X */
  1702. X#define CROSS_HAIR 20
  1703. Xselect_point(x,y)
  1704. Xint x,y;
  1705. X{
  1706. X  pw_vector(pw,x-CROSS_HAIR,y,x+CROSS_HAIR,y,PIX_XOR,1);
  1707. X  pw_vector(pw,x,y-CROSS_HAIR,x,y+CROSS_HAIR,PIX_XOR,1);
  1708. X}
  1709. X
  1710. X
  1711. X/*
  1712. X * reset the currently selected point
  1713. X */
  1714. Xreset_point()
  1715. X{
  1716. X  select_pt_x = 0-1;
  1717. X  select_pt_y = 0-1;
  1718. X}
  1719. X
  1720. X
  1721. X/*
  1722. X * take a currently selected region and invert that baby ! FAST !!!
  1723. X */
  1724. Xinverse_region()
  1725. X{
  1726. X  if (top_x || top_y || bottom_x || bottom_y)
  1727. X    {
  1728. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1729. X     region_fix();
  1730. X     pw_replrop(pw,top_x,top_y,bottom_x-top_x,bottom_y-top_y, PIX_XOR, pattern[0],0,0);
  1731. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1732. X    }
  1733. X  else
  1734. X    {
  1735. X     ERROR("Select a region first, then select INVERSE.");
  1736. X     panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1737. X     mouse_parms();
  1738. X    }
  1739. X}
  1740. X
  1741. X
  1742. X
  1743. X/*
  1744. X * take a currently selected region and rotate around the center
  1745. X * point.  SLOW !!
  1746. X */
  1747. Xrotate_region()
  1748. X{
  1749. Xregister i,j,t1,t2;
  1750. X
  1751. X  if (top_x || top_y || bottom_x || bottom_y)
  1752. X    {
  1753. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1754. X     region_fix();
  1755. X     MY_pr_destroy(cut_buffer_pr);
  1756. X     cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  1757. X     pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  1758. X        PIX_SRC,pw->pw_prretained,top_x,top_y);
  1759. X     t1 = top_x + cut_buffer_pr->pr_size.x/2+ cut_buffer_pr->pr_size.y/2;
  1760. X     t2 = top_y - cut_buffer_pr->pr_size.x/2+ cut_buffer_pr->pr_size.y/2;
  1761. X     for (j = 0; j < cut_buffer_pr->pr_size.y; j++)
  1762. X       for (i = 0; i < cut_buffer_pr->pr_size.x; i++)
  1763. X        pw_rop(pw, t1-j, t2+i, 1,1, PIX_SRC, cut_buffer_pr,i,j);
  1764. X
  1765. X     top_x = top_x + cut_buffer_pr->pr_size.x/2 - cut_buffer_pr->pr_size.y/2;
  1766. X     top_y = top_y - cut_buffer_pr->pr_size.x/2 + cut_buffer_pr->pr_size.y/2;
  1767. X     bottom_x = top_x + cut_buffer_pr->pr_size.y;
  1768. X     bottom_y = top_y + cut_buffer_pr->pr_size.x;
  1769. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1770. X    }
  1771. X  else
  1772. X    {
  1773. X     ERROR("Select a region first, then select ROTATE.");
  1774. X     panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1775. X     mouse_parms();
  1776. X    }
  1777. X}
  1778. X
  1779. X
  1780. X
  1781. X/*
  1782. X * take a currently selected region and make a mirror image of it
  1783. X */
  1784. Xflip_hor_region()
  1785. X{
  1786. Xregister i;
  1787. X  if (top_x || top_y || bottom_x || bottom_y)
  1788. X    {
  1789. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1790. X     region_fix();
  1791. X     MY_pr_destroy(cut_buffer_pr);
  1792. X     cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  1793. X     pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  1794. X        PIX_SRC,pw->pw_prretained,top_x,top_y);
  1795. X     for (i = 0; i < cut_buffer_pr->pr_size.x; i++) {
  1796. X        pw_rop(pw, top_x+(cut_buffer_pr->pr_size.x - i)-1,top_y,
  1797. X            1,cut_buffer_pr->pr_size.y, PIX_SRC, cut_buffer_pr,i,0);
  1798. X    }
  1799. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1800. X    }
  1801. X  else
  1802. X    {
  1803. X     ERROR("Select a region first, then select MIRROR.");
  1804. X     panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1805. X     mouse_parms();
  1806. X    }
  1807. X}
  1808. X
  1809. X
  1810. X/*
  1811. X * take a currently selected region and turn it upside down
  1812. X */
  1813. Xflip_ver_region()
  1814. X{
  1815. Xregister i;
  1816. X  if (top_x || top_y || bottom_x || bottom_y)
  1817. X    {
  1818. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1819. X     region_fix();
  1820. X     MY_pr_destroy(cut_buffer_pr);
  1821. X     cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  1822. X     pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  1823. X        PIX_SRC,pw->pw_prretained,top_x,top_y);
  1824. X     for (i = 0; i < cut_buffer_pr->pr_size.y; i++) {
  1825. X        pw_rop(pw, top_x, top_y+(cut_buffer_pr->pr_size.y - i)-1,
  1826. X            cut_buffer_pr->pr_size.x, 1, PIX_SRC, cut_buffer_pr, 0, i);
  1827. X    }
  1828. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1829. X    }
  1830. X  else
  1831. X    {
  1832. X     ERROR("Select a region first, then select FLIP VERTICAL.");
  1833. X     panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1834. X     mouse_parms();
  1835. X    }
  1836. X}
  1837. X
  1838. X
  1839. X
  1840. X/*
  1841. X * grab what is in the Cut/Paste buffer and put it up on the drawing area
  1842. X */
  1843. Xpaste_region()
  1844. X{
  1845. Xint ROP=PIX_SRC;
  1846. X
  1847. X  if (select_pt_x == -1)
  1848. X     {
  1849. X    ERROR("Select a point first, then select PASTE.");
  1850. X    set_select_mode();
  1851. X    return(0);
  1852. X     }
  1853. X  if (cut_buffer_pr)
  1854. X  {
  1855. X     select_point(select_pt_x,select_pt_y);
  1856. X     save_screen();
  1857. X     pw_write(pw,select_pt_x,select_pt_y,cut_buffer_pr->pr_size.x,cut_buffer_pr->pr_size.y, ROP, cut_buffer_pr,0,0);
  1858. X     reset_point();
  1859. X  }
  1860. X  else
  1861. X    ERROR("The Cut/Paste buffer is empty.");
  1862. X}
  1863. X
  1864. X
  1865. X/*
  1866. X * grab the currently selected region on the drawing area and stuff
  1867. X * it into the cut/paste buffer AND destroy the source area by
  1868. X * filling in with the current paint pattern
  1869. X */
  1870. Xcut_region()
  1871. X{
  1872. Xint t1,t2,t3,t4;
  1873. X  if (top_x || top_y || bottom_x || bottom_y)
  1874. X    {
  1875. X      t1 = top_x;
  1876. X      t2 = top_y;
  1877. X      t3 = bottom_x;
  1878. X      t4 = bottom_y;
  1879. X      copy_region();
  1880. X      top_x = t1;
  1881. X      top_y = t2;
  1882. X      bottom_x = t3;
  1883. X      bottom_y = t4;
  1884. X      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1885. X      fill_region();
  1886. X      set_select_mode();
  1887. X      print_msg("Region copied to Cut/Paste buffer, select a point and then press PASTE.");
  1888. X    }
  1889. X   else
  1890. X    {
  1891. X     ERROR("Select a region first, then select CUT.");
  1892. X     panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1893. X     mouse_parms();
  1894. X    }
  1895. X}
  1896. X
  1897. X
  1898. X/*
  1899. X * grab the currently selected region on the drawing area and stuff
  1900. X * it into the cut/paste buffer
  1901. X */
  1902. Xcopy_region()
  1903. X{
  1904. X  if (top_x || top_y || bottom_x || bottom_y)
  1905. X    {
  1906. X     select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1907. X     region_fix();
  1908. X     MY_pr_destroy(cut_buffer_pr);
  1909. X     cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  1910. X     pr_rop(cut_buffer_pr,0,0,bottom_x-top_x,bottom_y-top_y,
  1911. X        PIX_SRC,pw->pw_prretained,top_x,top_y);
  1912. X     reset_region();
  1913. X    }
  1914. X   else
  1915. X    {
  1916. X    ERROR("Select a region first, then select COPY.");
  1917. X        panel_set(command_choice,PANEL_VALUE,SEL_REG,0);
  1918. X        mouse_parms();
  1919. X    }
  1920. X}
  1921. X
  1922. X
  1923. X/*
  1924. X * take the cut/paste buffer and XOR it that stuff on to the drawing area
  1925. X * so that I can move that sucker around FAST
  1926. X */
  1927. Xmove_region(old_x,old_y,new_x,new_y)
  1928. Xint old_x,old_y,new_x,new_y;
  1929. X{
  1930. X  if (cut_buffer_pr)
  1931. X    {
  1932. X     pw_write(pw,old_x-cut_buffer_pr->pr_size.x/2,
  1933. X         old_y-cut_buffer_pr->pr_size.y/2,
  1934. X         cut_buffer_pr->pr_size.x,
  1935. X         cut_buffer_pr->pr_size.y,
  1936. X         PIX_XOR, cut_buffer_pr,0,0);
  1937. X
  1938. X     pw_write(pw,new_x-cut_buffer_pr->pr_size.x/2,
  1939. X         new_y-cut_buffer_pr->pr_size.y/2,
  1940. X         cut_buffer_pr->pr_size.x,
  1941. X         cut_buffer_pr->pr_size.y,
  1942. X         PIX_XOR, cut_buffer_pr,0,0);
  1943. X    }
  1944. X   else
  1945. X    {
  1946. X       ERROR("CUT or COPY a region first, then select MOVE.");
  1947. X    }
  1948. X}
  1949. X
  1950. X
  1951. X/*
  1952. X * fill in a rectanglar region with the current paint pattern
  1953. X */
  1954. Xfill_region(item, event)
  1955. XPanel_item      item;
  1956. XEvent           *event;
  1957. X{
  1958. X   if (top_x || top_y || bottom_x || bottom_y)
  1959. X    {
  1960. X      select_region(pw,top_x,top_y,bottom_x,bottom_y);
  1961. X      region_fix();
  1962. X      pw_replrop(pw,top_x,top_y,bottom_x-top_x,bottom_y-top_y,PIX_COLOR(cur_color) | PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],0,0);
  1963. X      reset_region();
  1964. X    }
  1965. X}
  1966. X
  1967. X
  1968. X/*
  1969. X * let the user lasso any free form region on the drawing area
  1970. X * and stuff that into the cut/paste buffer
  1971. X */
  1972. Xlaso_cut_paste()
  1973. X{
  1974. Xint found;
  1975. Xint i,no_points;
  1976. Xint npts[1];
  1977. X
  1978. X  top_x = image_wid;
  1979. X  top_y = image_hgt;
  1980. X  bottom_x = 0;
  1981. X  bottom_y = 0;
  1982. X
  1983. X  i=0;
  1984. X  while ((i<MAX_PTS) && (ptlist[i++].x != -1));
  1985. X  no_points = --i;
  1986. X  npts[0] = no_points; 
  1987. X  pw_polygon_2(pw,0,0,1,npts,ptlist,PIX_XOR,pattern[0],0,0);
  1988. X  pw_polygon_2(pw,0,0,1,npts,ptlist,PIX_XOR,pattern[0],0,0);
  1989. X
  1990. X  for (i=0;i < no_points;i++)
  1991. X    {
  1992. X        top_x = MIN(top_x,ptlist[i].x);
  1993. X        top_y = MIN(top_y,ptlist[i].y);
  1994. X        bottom_x = MAX(bottom_x,ptlist[i].x);
  1995. X        bottom_y = MAX(bottom_y,ptlist[i].y);
  1996. X        if (i>0)
  1997. X        pw_vector(pw,ptlist[i].x,ptlist[i].y,
  1998. X                 ptlist[i-1].x,ptlist[i-1].y,PIX_XOR,1);
  1999. X    }
  2000. X  for (i=0;i < no_points;i++)
  2001. X    {
  2002. X        ptlist[i].x -=top_x;
  2003. X        ptlist[i].y -=top_y;
  2004. X    }
  2005. X  MY_pr_destroy(cut_buffer_pr);
  2006. X  cut_buffer_pr = my_mem_create(bottom_x-top_x,bottom_y-top_y,image_depth);
  2007. X  pr_polygon_2(cut_buffer_pr,0,0,1,npts,ptlist,PIX_SRC,pw->pw_prretained,top_x,top_y);
  2008. X  reset_region();
  2009. X  print_msg("The selected area is now in the Cut/Paste buffer.");
  2010. X}
  2011. X
  2012. X
  2013. X/*
  2014. X * the user can lasso any area on the screen by just encircling the
  2015. X * object on the bitmap
  2016. X * we do this by remembering all of the points the mouse moved to
  2017. X * and make a polygon stencil from these points
  2018. X */
  2019. Xlaso_addpt(py_pts,x,y)
  2020. Xstruct pr_pos py_pts[];
  2021. Xint x,y;
  2022. X{
  2023. Xint found;
  2024. Xint i;
  2025. Xint npts[1];
  2026. X
  2027. X  found =0;
  2028. X  i=0;
  2029. X  while (i<MAX_PTS && !found)
  2030. X    {
  2031. X      if (py_pts[i++].x == -1)
  2032. X    found=TRUE;
  2033. X    }
  2034. X  i--;
  2035. X  npts[0] =i;
  2036. X        
  2037. X  py_pts[i].x = x;
  2038. X  py_pts[i].y = y;
  2039. X  if (i>0)
  2040. X    pw_vector(pw,py_pts[i].x,py_pts[i].y,py_pts[i-1].x,py_pts[i-1].y,PIX_XOR,1);
  2041. X  i++;
  2042. X  py_pts[i].x = 0-1;
  2043. X  py_pts[i].y = 0-1;
  2044. X}
  2045. X
  2046. X
  2047. X/*
  2048. X * add a point to the list of vetexs in the current polygon
  2049. X */
  2050. Xpoly_addpt(py_pts,x,y)
  2051. Xstruct pr_pos py_pts[];
  2052. Xint x,y;
  2053. X{
  2054. Xint found;
  2055. Xint i;
  2056. X
  2057. X  found =0;
  2058. X  i=0;
  2059. X  while (i<MAX_POLY && !found)
  2060. X    {
  2061. X      if (py_pts[i++].x == -1)
  2062. X    found=TRUE;
  2063. X    }
  2064. X  i--;
  2065. X       {
  2066. X         py_pts[i].x = x;
  2067. X         py_pts[i].y = y;
  2068. X     i++;
  2069. X     py_pts[i].x = 0-1;
  2070. X     py_pts[i].y = 0-1;
  2071. X       }
  2072. X}
  2073. X
  2074. X
  2075. X/*
  2076. X * take the list of currnet vertexs and draw up the
  2077. X * the polygon and fill it with the current paint pattern
  2078. X */
  2079. Xdraw_poly(py_pts)
  2080. Xstruct pr_pos py_pts[];
  2081. X{
  2082. Xint npts[1];
  2083. Xint found;
  2084. Xint i;
  2085. X
  2086. X  if (py_pts[0].x == 0-1)
  2087. X    return(0);
  2088. X
  2089. X  found =0;
  2090. X  i=0;
  2091. X  while (i<MAX_POLY && !found)
  2092. X    {
  2093. X      if (py_pts[i++].x == -1)
  2094. X    found=TRUE;
  2095. X    }
  2096. X  i--;
  2097. X
  2098. X  npts[0] =i;
  2099. X
  2100. X  /*
  2101. X   * do we want this baby filled ????
  2102. X   */ 
  2103. X  if ((int)panel_get_value(command_choice)==POLY_F)
  2104. X       pw_polygon_2(pw,0,0,1,npts,py_pts,PIX_COLOR(cur_color) | PIX_SRC,pattern[(int)panel_get_value(pattern_choice)],0,0);
  2105. X
  2106. X  /*
  2107. X   * do we want to wrap the polygon up in a vector border
  2108. X   */
  2109. X  if ((int)panel_get_value(border_cycle))
  2110. X  {
  2111. X      i=1;
  2112. X      while (i<MAX_POLY && (py_pts[i].x != -1))
  2113. X        {
  2114. X        pw_vector(pw,py_pts[i].x,py_pts[i].y,
  2115. X                 py_pts[i-1].x,py_pts[i-1].y,PIX_SRC,cur_color);
  2116. X        i++;
  2117. X        }
  2118. X      i--;
  2119. X      pw_vector(pw,py_pts[i].x,py_pts[i].y,
  2120. X                 py_pts[0].x,py_pts[0].y,PIX_SRC,cur_color);
  2121. X  }
  2122. X  clean_poly();
  2123. X}
  2124. X
  2125. X
  2126. X/*
  2127. X * reset the vertex list for the current polygon
  2128. X */
  2129. Xclean_poly()
  2130. X{
  2131. X  poly_points[0].x = 0-1;
  2132. X  poly_points[0].y = 0-1;
  2133. X}
  2134. END_OF_drawing.c
  2135. if test 16127 -ne `wc -c <drawing.c`; then
  2136.     echo shar: \"drawing.c\" unpacked with wrong size!
  2137. fi
  2138. # end of overwriting check
  2139. fi
  2140. if test -f fat.c -a "${1}" != "-c" ; then 
  2141.   echo shar: Will not over-write existing file \"fat.c\"
  2142. else
  2143. echo shar: Extracting \"fat.c\" \(5661 characters\)
  2144. sed "s/^X//" >fat.c <<'END_OF_fat.c'
  2145. X
  2146. X/**************************************************************************
  2147. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  2148. X   Copyright (c) 1988 by Raymond Kreisel
  2149. X   1/22/88 @ Suny Stony Brook
  2150. X
  2151. X   This program may be redistributed without fee as long as this copyright
  2152. X   notice is intact.
  2153. X
  2154. X==> PLEASE send comments and bug reports to one of the following addresses:
  2155. X
  2156. X       Ray Kreisel
  2157. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  2158. X
  2159. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  2160. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  2161. X       CSnet: rayk@suny-sb
  2162. X       (If nobody is home at any of the above addresses try:
  2163. X        S72QKRE@TOWSONVX.BITNET                    )
  2164. X
  2165. X "If I get home before daylight, I just might get some sleep tonight...."
  2166. X
  2167. X**************************************************************************/
  2168. X/**************************************************************************
  2169. X    file: fat.c
  2170. X    purpose: This file contains the functions that handle the
  2171. X        magnifing class command.
  2172. X
  2173. X    modifications:
  2174. X        date:    Tue Mar 22 22:04:58 EST 1988
  2175. X        author:    rayk
  2176. X        changes:add comments
  2177. X**************************************************************************/
  2178. X
  2179. X#include "header.h"
  2180. X
  2181. Xint old_cur_color=0-1;
  2182. X
  2183. X/*
  2184. X * Let's go into magnify mode !!
  2185. X */
  2186. Xfat_mode(item, event)
  2187. XPanel_item      item;
  2188. XEvent           *event;
  2189. X{
  2190. X    if (image_depth==1)
  2191. X    old_cur_color = cur_color;
  2192. X    if (select_pt_x == -1)
  2193. X       {
  2194. X    ERROR("Select point first then select Magnify");
  2195. X    set_select_mode();
  2196. X    return(0);
  2197. X       }
  2198. X    
  2199. X    if (fat_source_x != -1)
  2200. X       select_fat_region();
  2201. X    fat_source_x = select_pt_x- (int)window_get(fat_canvas, CANVAS_WIDTH)/magnify_fac/2;
  2202. X    fat_source_y = select_pt_y- (int)window_get(fat_canvas, CANVAS_HEIGHT)/magnify_fac/2;
  2203. X    clean_point();
  2204. X    (void)window_set(fat_frame, WIN_SHOW, TRUE, 0);
  2205. X    select_fat_region();
  2206. X    fat_update(0,0);
  2207. X}
  2208. X
  2209. X
  2210. X/*
  2211. X * kill off the magnify window
  2212. X */
  2213. Xfat_done(item, event)
  2214. XPanel_item      item;
  2215. XEvent           *event;
  2216. X{
  2217. X    if ((image_depth==1) && (old_cur_color != -1))
  2218. X    {
  2219. X    cur_color = old_cur_color;
  2220. X        old_cur_color = 0-1;
  2221. X    }
  2222. X    if (fat_source_x != -1)
  2223. X       select_fat_region();
  2224. X    (void)window_set(fat_frame, WIN_SHOW, FALSE, 0);
  2225. X    fat_source_x = 0-1;
  2226. X    fat_source_y = 0-1;
  2227. X}
  2228. X
  2229. X
  2230. X
  2231. X/*
  2232. X * The event handler for the canvas of the magnifying class window
  2233. X * You can do 3 things.
  2234. X *  left: inverse the bit the mouse is on top of and continue
  2235. X *        to draw in that color
  2236. X *  middle: use this to draw the magnified view
  2237. X *  right: use to set the current color to the color of the pixel
  2238. X *         under the cursor
  2239. X */
  2240. Xfat_handle_event(canvas_local, event)
  2241. XCanvas  canvas_local;
  2242. XEvent   *event;
  2243. X{
  2244. X    if (event_is_up(event))
  2245. X       return;
  2246. X    switch (event_id(event)) {
  2247. X     case MS_LEFT:
  2248. X        if (image_depth ==1)
  2249. X                   {
  2250. X              cur_color = 1^pw_get(pw,fat_source_x + (int)event_x(event)/magnify_fac,fat_source_y + (int)event_y(event)/magnify_fac);
  2251. X           }
  2252. X        fat_draw(fat_pw,pw, event_x(event), event_y(event));
  2253. X        break;
  2254. X     case MS_MIDDLE:
  2255. X        fat_x = event_x(event);
  2256. X        fat_y = event_y(event);
  2257. X        break;
  2258. X     case MS_RIGHT:
  2259. X         fat_match_color(event_x(event), event_y(event));
  2260. X                break;
  2261. X         case LOC_DRAG:
  2262. X            if (window_get(canvas_local, WIN_EVENT_STATE, MS_LEFT))
  2263. X        fat_draw(fat_pw,pw, event_x(event), event_y(event));
  2264. X        else if (window_get(canvas_local, WIN_EVENT_STATE, MS_MIDDLE))
  2265. X        {
  2266. X        fat_update(fat_x-event_x(event),fat_y-event_y(event));
  2267. X        fat_x = event_x(event);
  2268. X        fat_y = event_y(event);
  2269. X        }
  2270. X        break;
  2271. X
  2272. X    }
  2273. X}
  2274. X
  2275. X
  2276. X/*
  2277. X * Find out the color of the pixel under the cursor
  2278. X */
  2279. Xfat_match_color(x,y)
  2280. Xint x,y;
  2281. X{
  2282. X  x = fat_source_x + x/magnify_fac;
  2283. X  y = fat_source_y + y/magnify_fac;
  2284. X  update_cur_color(0,0,pw_get(pw,x,y));
  2285. X}
  2286. X
  2287. X
  2288. X/*
  2289. X * This is the function that updates the display of the magnifyied view
  2290. X * This function is called when the middle but is used to draw this window
  2291. X */
  2292. Xfat_update(offset_x,offset_y)
  2293. Xint offset_x,offset_y;
  2294. X{
  2295. Xint w,h;
  2296. X
  2297. X  w = (int) window_get(fat_canvas, CANVAS_WIDTH);
  2298. X  h = (int) window_get(fat_canvas, CANVAS_HEIGHT);
  2299. X  select_fat_region();
  2300. X  fat_source_x += offset_x/magnify_fac;
  2301. X  fat_source_y += offset_y/magnify_fac;
  2302. X  if (w >= SCREEN_MAX_X)
  2303. X     w=SCREEN_MAX_X-1;
  2304. X  if (h >= SCREEN_MAX_Y)
  2305. X     h=SCREEN_MAX_Y-1;
  2306. X
  2307. X/*
  2308. X * check if you are within the pixrect
  2309. X */
  2310. X#ifdef NO_FASTAN
  2311. X  if (fat_source_x < 0)
  2312. X    fat_source_x = 0;
  2313. X  if (fat_source_y < 0)
  2314. X    fat_source_y = 0;
  2315. X  if (fat_source_x+w/magnify_fac > image_wid)
  2316. X    fat_source_x = image_wid - w/magnify_fac;
  2317. X  if (fat_source_y+h/magnify_fac > image_hgt)
  2318. X    fat_source_y = image_hgt - h/magnify_fac;
  2319. X#endif
  2320. X
  2321. X  pw_mag(fat_pw, 0, 0, w, h, magnify_fac, pw->pw_prretained,
  2322. X     fat_source_x, fat_source_y);
  2323. X  select_fat_region();
  2324. X}
  2325. X
  2326. X
  2327. X/*
  2328. X * get the current magnification level
  2329. X */
  2330. Xfat_parms(item, event)
  2331. XPanel_item      item;
  2332. XEvent           *event;
  2333. X{
  2334. X  select_fat_region();
  2335. X  magnify_fac = (int)panel_get_value(magnify_cycle) + 1;
  2336. X  select_fat_region();
  2337. X  fat_update(0,0);
  2338. X}
  2339. X
  2340. X
  2341. X/*
  2342. X * show which region of the drawing area bitmap is being magnified
  2343. X */
  2344. Xselect_fat_region()
  2345. X{
  2346. Xint w,h;
  2347. X  w = (int) window_get(fat_canvas, CANVAS_WIDTH);
  2348. X  h = (int) window_get(fat_canvas, CANVAS_HEIGHT);
  2349. X  select_region(pw,fat_source_x-1,fat_source_y-1,
  2350. X          fat_source_x+w/magnify_fac+1,fat_source_y+h/magnify_fac+1);
  2351. X}
  2352. X
  2353. X
  2354. X
  2355. X/*
  2356. X * handle the drawing inside of the magnified view window
  2357. X */
  2358. Xfat_draw(fat_pw,pw,x,y)
  2359. Xstruct pixwin *fat_pw,*pw;
  2360. Xint x,y;
  2361. X{
  2362. X  x = x/magnify_fac*magnify_fac;
  2363. X  y = y/magnify_fac*magnify_fac;
  2364. X  pw_write(fat_pw,x,y,magnify_fac,magnify_fac,PIX_COLOR(cur_color) | PIX_SRC,NILPR,0,0);
  2365. X  x = fat_source_x + x/magnify_fac;
  2366. X  y = fat_source_y + y/magnify_fac;
  2367. X  pw_put(pw,x,y,cur_color);
  2368. X}
  2369. X
  2370. END_OF_fat.c
  2371. if test 5661 -ne `wc -c <fat.c`; then
  2372.     echo shar: \"fat.c\" unpacked with wrong size!
  2373. fi
  2374. # end of overwriting check
  2375. fi
  2376. if test -f ffill.c -a "${1}" != "-c" ; then 
  2377.   echo shar: Will not over-write existing file \"ffill.c\"
  2378. else
  2379. echo shar: Extracting \"ffill.c\" \(2770 characters\)
  2380. sed "s/^X//" >ffill.c <<'END_OF_ffill.c'
  2381. X
  2382. X/**************************************************************************
  2383. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  2384. X   Copyright (c) 1988 by Raymond Kreisel
  2385. X   1/22/88 @ Suny Stony Brook
  2386. X
  2387. X   This program may be redistributed without fee as long as this copyright
  2388. X   notice is intact.
  2389. X
  2390. X==> PLEASE send comments and bug reports to one of the following addresses:
  2391. X
  2392. X       Ray Kreisel
  2393. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  2394. X
  2395. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  2396. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  2397. X       CSnet: rayk@suny-sb
  2398. X       (If nobody is home at any of the above addresses try:
  2399. X        S72QKRE@TOWSONVX.BITNET                    )
  2400. X
  2401. X "If I get home before daylight, I just might get some sleep tonight...."
  2402. X
  2403. X**************************************************************************/
  2404. X/**************************************************************************
  2405. X    file: ffill.c
  2406. X    purpose: this file has the functions that do flood fill
  2407. X
  2408. X    modifications:
  2409. X        date:    Tue Mar 22 22:04:58 EST 1988
  2410. X        author:    rayk
  2411. X        changes:add comments
  2412. X**************************************************************************/
  2413. X
  2414. X#include "header.h"
  2415. X
  2416. X
  2417. X/*
  2418. X * let's go into flood fill mode because we got a button click on flood fill
  2419. X */
  2420. Xfill_mode(item, event)
  2421. XPanel_item      item;
  2422. XEvent           *event;
  2423. X{
  2424. Xint x,y;
  2425. X
  2426. X
  2427. X  if (select_pt_x != -1)
  2428. X      {
  2429. X         print_msg("Hold down the RIGHT mouse button to cancel flood fill.");
  2430. X       x = select_pt_x;
  2431. X         y = select_pt_y;
  2432. X     clean_point();
  2433. X     save_screen();
  2434. X     pw_put(pw,x,y,cur_color^1);
  2435. X     if (ffill(x,y,cur_color))
  2436. X        ERROR("Flood fill cancelled !!");
  2437. X     else
  2438. X        hide_msg();
  2439. X      }
  2440. X  else
  2441. X      {
  2442. X    ERROR("Select point first, then select flood fill");
  2443. X    set_select_mode();
  2444. X      }
  2445. X}
  2446. X
  2447. X
  2448. X#define FILL_CANCEL 1
  2449. X
  2450. X/*
  2451. X * this is a simple recursive flood fill that will work
  2452. X * on mono bitmaps
  2453. X * call it will the start x,y coordinates and the color
  2454. X * to fill with, which is also the bounary color
  2455. X */
  2456. Xffill(x,y,n)
  2457. Xint x,y,n;
  2458. X{
  2459. Xint flag;
  2460. Xregister i,j,k,bx;
  2461. X
  2462. X        if (window_get(canvas, WIN_EVENT_STATE, MS_RIGHT))
  2463. X            return(FILL_CANCEL);
  2464. X
  2465. X    if (x<0 || x>=image_wid || y<0 || y>=image_hgt || pw_get(pw,x,y)==n)
  2466. X        return(0);
  2467. X    pw_put(pw,x,y,n);
  2468. X        bx = x-1;
  2469. X    for (i=x-1;i>=0;i--) {
  2470. X        if (pw_get(pw,i,y)!=n)
  2471. X            bx = i;
  2472. X        else 
  2473. X            {
  2474. X            pw_vector(pw,bx,y,x,y, PIX_SRC,n);
  2475. X            break;
  2476. X            }
  2477. X        }
  2478. X        bx = x+1;
  2479. X    for (j=x+1;j<image_wid;j++)
  2480. X        if (pw_get(pw,j,y)!=n)
  2481. X            bx = j;
  2482. X        else 
  2483. X             {
  2484. X            pw_vector(pw,bx,y,x,y, PIX_SRC,n);
  2485. X            break;
  2486. X             }
  2487. X
  2488. X        flag = 0;
  2489. X    for (k=i+1;k<j;k++)
  2490. X    {
  2491. X        if (y>0 && pw_get(pw,k,y-1)!=n)
  2492. X            flag = ffill(k,y-1,n);
  2493. X        if (y<image_hgt-1 && pw_get(pw,k,y+1)!=n)
  2494. X            flag = ffill(k,y+1,n);
  2495. X                if (flag) break;
  2496. X    }
  2497. Xreturn(flag);
  2498. X}
  2499. X
  2500. END_OF_ffill.c
  2501. if test 2770 -ne `wc -c <ffill.c`; then
  2502.     echo shar: \"ffill.c\" unpacked with wrong size!
  2503. fi
  2504. # end of overwriting check
  2505. fi
  2506. if test -f fonts.c -a "${1}" != "-c" ; then 
  2507.   echo shar: Will not over-write existing file \"fonts.c\"
  2508. else
  2509. echo shar: Extracting \"fonts.c\" \(4529 characters\)
  2510. sed "s/^X//" >fonts.c <<'END_OF_fonts.c'
  2511. X
  2512. X/**************************************************************************
  2513. X   Touchup a bitmap graphics editor for the Sun Workstation running SunView
  2514. X   Copyright (c) 1988 by Raymond Kreisel
  2515. X   1/22/88 @ Suny Stony Brook
  2516. X
  2517. X   This program may be redistributed without fee as long as this copyright
  2518. X   notice is intact.
  2519. X
  2520. X==> PLEASE send comments and bug reports to one of the following addresses:
  2521. X
  2522. X       Ray Kreisel
  2523. X       CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  2524. X
  2525. X       UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  2526. X       ARPA-Internet: rayk@sbcs.sunysb.edu            
  2527. X       CSnet: rayk@suny-sb
  2528. X       (If nobody is home at any of the above addresses try:
  2529. X        S72QKRE@TOWSONVX.BITNET                    )
  2530. X
  2531. X "If I get home before daylight, I just might get some sleep tonight...."
  2532. X
  2533. X**************************************************************************/
  2534. X/**************************************************************************
  2535. X    file: fonts
  2536. X    purpose: the get most of the good system fixed width fonts
  2537. X        from the sys dirs and set them up in memory
  2538. X
  2539. X    modifications:
  2540. X        date:    Tue Mar 22 22:04:58 EST 1988
  2541. X        author:    rayk
  2542. X        changes:add comments
  2543. X**************************************************************************/
  2544. X
  2545. X#include <pixrect/pixrect_hs.h>
  2546. X
  2547. X
  2548. X
  2549. X#define cour_b_10F  "/usr/lib/fonts/fixedwidthfonts/cour.b.10"
  2550. X#define cour_b_12F  "/usr/lib/fonts/fixedwidthfonts/cour.b.12"
  2551. X#define cour_b_16F  "/usr/lib/fonts/fixedwidthfonts/cour.b.16"
  2552. X#define cour_b_24F  "/usr/lib/fonts/fixedwidthfonts/cour.b.24"
  2553. X
  2554. X#define cour_r_10F  "/usr/lib/fonts/fixedwidthfonts/cour.r.10"
  2555. X#define cour_r_12F  "/usr/lib/fonts/fixedwidthfonts/cour.r.12"
  2556. X#define cour_r_16F  "/usr/lib/fonts/fixedwidthfonts/cour.r.16"
  2557. X#define cour_r_24F  "/usr/lib/fonts/fixedwidthfonts/cour.r.24"
  2558. X
  2559. X#define screen_r_7F   "/usr/lib/fonts/fixedwidthfonts/screen.r.7"
  2560. X#define screen_r_11F  "/usr/lib/fonts/fixedwidthfonts/screen.r.11"
  2561. X#define screen_r_12F  "/usr/lib/fonts/fixedwidthfonts/screen.r.12"
  2562. X#define screen_r_14F  "/usr/lib/fonts/fixedwidthfonts/screen.r.14"
  2563. X#define screen_b_12F  "/usr/lib/fonts/fixedwidthfonts/screen.b.12"
  2564. X#define screen_b_14F  "/usr/lib/fonts/fixedwidthfonts/screen.b.14"
  2565. X
  2566. X#define pcfont_b_14F  "/usr/lib/fonts/fixedwidthfonts/pcfont.b.14"
  2567. X#define pcfont_r_14F  "/usr/lib/fonts/fixedwidthfonts/pcfont.r.14"
  2568. X
  2569. X#define serif_r_10F  "/usr/lib/fonts/fixedwidthfonts/serif.r.10"
  2570. X#define serif_r_11F  "/usr/lib/fonts/fixedwidthfonts/serif.r.11"
  2571. X#define serif_r_16F  "/usr/lib/fonts/fixedwidthfonts/serif.r.16"
  2572. X
  2573. Xstruct  pixfont  *screen_r_7;
  2574. Xstruct  pixfont  *screen_r_11;
  2575. Xstruct  pixfont  *screen_r_12;
  2576. Xstruct  pixfont  *screen_r_14;
  2577. Xstruct  pixfont  *screen_b_12;
  2578. Xstruct  pixfont  *screen_b_14;
  2579. X
  2580. Xstruct  pixfont  *pcfont_b_14;
  2581. Xstruct  pixfont  *pcfont_r_14;
  2582. X
  2583. Xstruct  pixfont  *cour_b_10;
  2584. Xstruct  pixfont  *cour_b_12;
  2585. Xstruct  pixfont  *cour_b_16;
  2586. Xstruct  pixfont  *cour_b_24;
  2587. X
  2588. Xstruct  pixfont  *cour_r_10;
  2589. Xstruct  pixfont  *cour_r_12;
  2590. Xstruct  pixfont  *cour_r_14;
  2591. Xstruct  pixfont  *cour_r_16;
  2592. Xstruct  pixfont  *cour_r_18;
  2593. Xstruct  pixfont  *cour_r_24;
  2594. X
  2595. Xstruct  pixfont  *serif_r_10;
  2596. Xstruct  pixfont  *serif_r_11;
  2597. Xstruct  pixfont  *serif_r_16;
  2598. X
  2599. X
  2600. X#define FONT_NO 19
  2601. X
  2602. X
  2603. Xstruct  pixfont  *font_array[FONT_NO];
  2604. X
  2605. Xinit_font()
  2606. X{
  2607. X
  2608. X   screen_r_7  = pf_open(screen_r_7F);
  2609. X   screen_r_11 = pf_open(screen_r_11F);
  2610. X   screen_r_12 = pf_open(screen_r_12F);
  2611. X   screen_r_14 = pf_open(screen_r_14F);
  2612. X   screen_b_12 = pf_open(screen_b_12F);
  2613. X   screen_b_14 = pf_open(screen_b_14F);
  2614. X
  2615. X   pcfont_b_14 = pf_open(pcfont_b_14F);
  2616. X   pcfont_r_14 = pf_open(pcfont_r_14F);
  2617. X
  2618. X   cour_b_10 = pf_open(cour_b_10F); 
  2619. X   cour_b_12 = pf_open(cour_b_12F);
  2620. X   cour_b_16 = pf_open(cour_b_16F);
  2621. X   cour_b_24 = pf_open(cour_b_24F); 
  2622. X
  2623. X   cour_r_10 = pf_open(cour_r_10F);
  2624. X   cour_r_12 = pf_open(cour_r_12F);
  2625. X   cour_r_16 = pf_open(cour_r_16F);
  2626. X   cour_r_24 = pf_open(cour_r_24F);
  2627. X
  2628. X   serif_r_10 = pf_open(serif_r_10F);           
  2629. X   serif_r_11 = pf_open(serif_r_11F);          
  2630. X   serif_r_16 = pf_open(serif_r_16F);
  2631. X
  2632. X  font_array[0] = cour_r_10;
  2633. X  font_array[1] = cour_r_12;
  2634. X  font_array[2] = cour_r_16;
  2635. X  font_array[3] = cour_r_24;
  2636. X
  2637. X  font_array[4] = cour_b_10;
  2638. X  font_array[5] = cour_b_12;
  2639. X  font_array[6] = cour_b_16;
  2640. X  font_array[7] = cour_b_24;
  2641. X
  2642. X  font_array[8] = serif_r_10;
  2643. X  font_array[9] = serif_r_11;
  2644. X  font_array[10] = serif_r_16;
  2645. X
  2646. X  font_array[11] = screen_r_7;
  2647. X  font_array[12] = screen_r_11;
  2648. X  font_array[13] = screen_r_12;
  2649. X  font_array[14] = screen_r_14;
  2650. X  font_array[15] = screen_b_12;
  2651. X  font_array[16] = screen_b_14;
  2652. X
  2653. X  font_array[17] = pcfont_b_14;
  2654. X  font_array[18] = pcfont_r_14;
  2655. X}
  2656. X
  2657. END_OF_fonts.c
  2658. if test 4529 -ne `wc -c <fonts.c`; then
  2659.     echo shar: \"fonts.c\" unpacked with wrong size!
  2660. fi
  2661. # end of overwriting check
  2662. fi
  2663. echo shar: End of archive 5 \(of 6\).
  2664. cp /dev/null ark5isdone
  2665. MISSING=""
  2666. for I in 1 2 3 4 5 6 ; do
  2667.     if test ! -f ark${I}isdone ; then
  2668.     MISSING="${MISSING} ${I}"
  2669.     fi
  2670. done
  2671. if test "${MISSING}" = "" ; then
  2672.     echo You have unpacked all 6 archives.
  2673.     rm -f ark[1-9]isdone
  2674. else
  2675.     echo You still need to unpack the following archives:
  2676.     echo "        " ${MISSING}
  2677. fi
  2678. ##  End of shell archive.
  2679. exit 0
  2680.